-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: Refactor pandas/tests/base - part3 #30147
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
jreback
merged 27 commits into
pandas-dev:master
from
SaturnFromTitan:refactor-test-base-part3
Feb 1, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4d1750c
added new fixtures that can replace the Ops mixin
SaturnFromTitan 3d04ff2
fixed type hinting
SaturnFromTitan 89d84b4
refactoring according to review comments
SaturnFromTitan 199896f
removing unused variable arr and fixing the _narrow_series data
SaturnFromTitan e269b09
removing usage of Ops mixin in tests/indexes
SaturnFromTitan baab827
moved new fixtures to tests/indexes/conftest.py as they're not used a…
SaturnFromTitan 28291f1
using new utils and fixtures in tests/indexes
SaturnFromTitan 589ae3b
fixturizing tests/base/test_ops.py::test_binary_ops_docs
SaturnFromTitan 2bbc3fd
refactoring of tests/indexes/conftest.py
SaturnFromTitan b3d0252
using pytest.skip instead of early return
SaturnFromTitan 53db63f
skipping broken tests
SaturnFromTitan 891b24c
replaced more return statements with pytest.skip
SaturnFromTitan 8f0fdf6
Merge branch 'master' into refactor-test-base-part3
SaturnFromTitan 69a0a0d
took care of review comments
SaturnFromTitan 0fce4c5
removed redundant tests
SaturnFromTitan b7892fa
removed changes that aren't needed for this PR anymore
SaturnFromTitan 471f217
moved helper to more appropriate location
SaturnFromTitan baa4965
Merge branch 'master' into refactor-test-base-part3
SaturnFromTitan 7562479
removed some outdated changes
SaturnFromTitan 85b16cb
moved datetime_series fixture to the root conftest so it's available …
SaturnFromTitan 87e0a5b
using all_arithmetic_functions in test_binary_ops_docs now
SaturnFromTitan 3979b3d
undid some unrelated changes
SaturnFromTitan 452335a
Merge branch 'master' into refactor-test-base-part3
SaturnFromTitan 8bf1142
undid my change in pandas/core/ops/__init__.py and handle the case di…
SaturnFromTitan c1e9f28
Revert "undid my change in pandas/core/ops/__init__.py and handle the…
SaturnFromTitan d9bea94
Merge branch 'master' into refactor-test-base-part3
SaturnFromTitan 87247a5
using hard-coded values to parametrize test_binary_ops
SaturnFromTitan 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
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,59 @@ | ||
from typing import Any, Callable, List | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
SaturnFromTitan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from pandas import Index, Series | ||
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin | ||
import pandas.util.testing as tm | ||
|
||
|
||
def allow_na_ops(obj: Any) -> bool: | ||
SaturnFromTitan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Whether to skip test cases including NaN""" | ||
is_bool_index = isinstance(obj, Index) and obj.is_boolean() | ||
return not is_bool_index and obj._can_hold_na | ||
|
||
|
||
def check_ops_properties_valid(obj: Any, props: List[str], filter: Callable) -> None: | ||
""" Validates that certain properties are available """ | ||
for op in props: | ||
# if a filter, skip if it doesn't match | ||
index = obj.index if isinstance(obj, Series) else obj | ||
if not filter(index): | ||
continue | ||
|
||
try: | ||
if isinstance(obj, Series): | ||
expected = Series(getattr(obj.index, op), index=obj.index, name="a") | ||
else: | ||
expected = getattr(obj, op) | ||
except AttributeError: | ||
continue | ||
|
||
result = getattr(obj, op) | ||
|
||
# these could be series, arrays or scalars | ||
if isinstance(result, Series) and isinstance(expected, Series): | ||
tm.assert_series_equal(result, expected) | ||
elif isinstance(result, Index) and isinstance(expected, Index): | ||
tm.assert_index_equal(result, expected) | ||
elif isinstance(result, np.ndarray) and isinstance(expected, np.ndarray): | ||
tm.assert_numpy_array_equal(result, expected) | ||
else: | ||
assert result == expected | ||
|
||
|
||
def check_ops_properties_invalid(obj: Any, props: List[str]) -> None: | ||
""" Validates that certain properties are not available """ | ||
for op in props: | ||
# freq raises AttributeError on an Int64Index because its not | ||
# defined we mostly care about Series here anyhow | ||
|
||
# an object that is datetimelike will raise a TypeError, | ||
# otherwise an AttributeError | ||
err = AttributeError | ||
if issubclass(type(obj), DatetimeIndexOpsMixin): | ||
err = TypeError | ||
|
||
with pytest.raises(err): | ||
getattr(obj, op) | ||
SaturnFromTitan marked this conversation as resolved.
Show resolved
Hide resolved
|
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.