-
Notifications
You must be signed in to change notification settings - Fork 103
test: refactor test_data_color_utils.py
through parametrization
#740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FBruzzesi
wants to merge
4
commits into
posit-dev:main
Choose a base branch
from
FBruzzesi:test/refactor-data-color-utils
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+465
−513
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a78bb2
test: refactor test_data_color_utils.py through parametrization
FBruzzesi 755ea44
parse version with _tbl_data _re_version func
FBruzzesi 81420c7
Merge branch 'main' into test/refactor-data-color-utils
FBruzzesi c172954
Merge branch 'main' into test/refactor-data-color-utils
FBruzzesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,10 @@ | |
PlSelectExpr = _selector_proxy_ | ||
PlExpr = pl.Expr | ||
|
||
PdSeries = pd.Series | ||
PdSeries = pd.Series[Any] | ||
PlSeries = pl.Series | ||
PyArrowArray = pa.Array | ||
PyArrowChunkedArray = pa.ChunkedArray | ||
PyArrowArray = pa.Array[Any] | ||
PyArrowChunkedArray = pa.ChunkedArray[Any] | ||
|
||
PdNA = pd.NA | ||
PlNull = pl.Null | ||
|
@@ -763,7 +763,7 @@ def _(df: PyArrowTable, x: Any) -> bool: | |
import pyarrow as pa | ||
|
||
arr = pa.array([x]) | ||
return arr.is_null().to_pylist()[0] or arr.is_nan().to_pylist()[0] | ||
return arr.is_null(nan_is_null=True).to_pylist()[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for this change is that |
||
|
||
|
||
@singledispatch | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from __future__ import annotations | ||
|
||
from importlib.util import find_spec | ||
|
||
import pytest | ||
|
||
from great_tables._tbl_data import DataFrameLike, _re_version | ||
from tests.utils import DataFrameConstructor, DataLike | ||
|
||
|
||
def pandas_constructor(obj: DataLike) -> DataFrameLike: | ||
import pandas as pd | ||
|
||
return pd.DataFrame(obj) # type: ignore[no-any-return] | ||
|
||
|
||
def pandas_nullable_constructor(obj: DataLike) -> DataFrameLike: | ||
import pandas as pd | ||
|
||
return pd.DataFrame(obj).convert_dtypes(dtype_backend="numpy_nullable") # type: ignore[no-any-return] | ||
|
||
|
||
def pandas_pyarrow_constructor(obj: DataLike) -> DataFrameLike: | ||
import pandas as pd | ||
|
||
return pd.DataFrame(obj).convert_dtypes(dtype_backend="pyarrow") # type: ignore[no-any-return] | ||
|
||
|
||
def polars_constructor(obj: DataLike) -> DataFrameLike: | ||
import polars as pl | ||
|
||
return pl.DataFrame(obj) | ||
|
||
|
||
def pyarrow_table_constructor(obj: DataLike) -> DataFrameLike: | ||
import pyarrow as pa | ||
|
||
return pa.table(obj) # type: ignore[no-any-return] | ||
|
||
|
||
frame_constructors: list[DataFrameConstructor] = [] | ||
|
||
is_pandas_installed = find_spec("pandas") is not None | ||
is_polars_installed = find_spec("polars") is not None | ||
is_pyarrow_installed = find_spec("pyarrow") is not None | ||
|
||
if is_pandas_installed: | ||
import pandas as pd | ||
|
||
frame_constructors.append(pandas_constructor) | ||
|
||
pandas_ge_v2 = _re_version(pd.__version__) >= (2, 0, 0) | ||
|
||
if pandas_ge_v2: | ||
frame_constructors.append(pandas_nullable_constructor) | ||
|
||
if pandas_ge_v2 and is_pyarrow_installed: | ||
# pandas 2.0+ supports pyarrow dtype backend | ||
# https://pandas.pydata.org/docs/whatsnew/v2.0.0.html#new-dtype-backends | ||
frame_constructors.append(pandas_pyarrow_constructor) | ||
|
||
if is_polars_installed: | ||
frame_constructors.append(polars_constructor) | ||
|
||
if is_pyarrow_installed: | ||
frame_constructors.append(pyarrow_table_constructor) | ||
|
||
|
||
@pytest.fixture(params=frame_constructors) | ||
def frame_constructor(request: pytest.FixtureRequest) -> DataFrameConstructor: | ||
return request.param # type: ignore[no-any-return] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason for this is that I was getting warnings that