-
Notifications
You must be signed in to change notification settings - Fork 322
fix: use pandas function to check for NaN #750
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ebdc683
fix: use pandas function to check for NaN
LinuxChristian f86d103
tests: Skip tests if pandas below required version
LinuxChristian 659e9f7
tests: compare expected and actual directly as lists
LinuxChristian dc0529b
Fix pytest.mark.skipif spelling
plamut 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
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import operator | ||
| import queue | ||
| import warnings | ||
| import pkg_resources | ||
|
|
||
| import mock | ||
|
|
||
|
|
@@ -47,6 +48,14 @@ | |
| except ImportError: # pragma: NO COVER | ||
| bigquery_storage = None | ||
|
|
||
| PANDAS_MINIUM_VERSION = pkg_resources.parse_version("1.0.0") | ||
|
|
||
| if pandas is not None: | ||
| PANDAS_INSTALLED_VERSION = pkg_resources.get_distribution("pandas").parsed_version | ||
| else: | ||
| # Set to less than MIN version. | ||
| PANDAS_INSTALLED_VERSION = pkg_resources.parse_version("0.0.0") | ||
|
|
||
|
|
||
| skip_if_no_bignumeric = pytest.mark.skipif( | ||
| not _BIGNUMERIC_SUPPORT, reason="BIGNUMERIC support requires pyarrow>=3.0.0", | ||
|
|
@@ -734,6 +743,38 @@ def test_list_columns_and_indexes_with_named_index_same_as_column_name( | |
| assert columns_and_indexes == expected | ||
|
|
||
|
|
||
| @pytest.mark.skipIf( | ||
| pandas is None or PANDAS_INSTALLED_VERSION < PANDAS_MINIUM_VERSION, | ||
| reason="Requires `pandas version >= 1.0.0` which introduces pandas.NA", | ||
|
Contributor
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. Neat to also include the reason why a minimum version is needed. 👍 |
||
| ) | ||
| def test_dataframe_to_json_generator(module_under_test): | ||
| utcnow = datetime.datetime.utcnow() | ||
| df_data = collections.OrderedDict( | ||
| [ | ||
| ("a_series", [pandas.NA, 2, 3, 4]), | ||
| ("b_series", [0.1, float("NaN"), 0.3, 0.4]), | ||
| ("c_series", ["a", "b", pandas.NA, "d"]), | ||
plamut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ("d_series", [utcnow, utcnow, utcnow, pandas.NaT]), | ||
| ("e_series", [True, False, True, None]), | ||
| ] | ||
| ) | ||
| dataframe = pandas.DataFrame( | ||
| df_data, index=pandas.Index([4, 5, 6, 7], name="a_index") | ||
| ) | ||
|
|
||
| dataframe = dataframe.astype({"a_series": pandas.Int64Dtype()}) | ||
|
|
||
| rows = module_under_test.dataframe_to_json_generator(dataframe) | ||
| expected = [ | ||
| {"b_series": 0.1, "c_series": "a", "d_series": utcnow, "e_series": True}, | ||
| {"a_series": 2, "c_series": "b", "d_series": utcnow, "e_series": False}, | ||
| {"a_series": 3, "b_series": 0.3, "d_series": utcnow, "e_series": True}, | ||
| {"a_series": 4, "b_series": 0.4, "c_series": "d"}, | ||
| ] | ||
| for row, expect in zip(rows, expected): | ||
plamut marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert row == expect | ||
|
|
||
|
|
||
| @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") | ||
| def test_list_columns_and_indexes_with_named_index(module_under_test): | ||
| df_data = collections.OrderedDict( | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.