-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Clean test_arithmetic.py #36390
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
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -271,7 +271,6 @@ def test_comparison_flex_basic(self): | |
tm.assert_series_equal(left.gt(right), left > right) | ||
tm.assert_series_equal(left.ge(right), left >= right) | ||
|
||
# axis | ||
for axis in [0, None, "index"]: | ||
tm.assert_series_equal(left.eq(right, axis=axis), left == right) | ||
tm.assert_series_equal(left.ne(right, axis=axis), left != right) | ||
|
@@ -280,7 +279,6 @@ def test_comparison_flex_basic(self): | |
tm.assert_series_equal(left.gt(right, axis=axis), left > right) | ||
tm.assert_series_equal(left.ge(right, axis=axis), left >= right) | ||
|
||
# | ||
msg = "No axis named 1 for object type" | ||
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. could use the fixture |
||
for op in ["eq", "ne", "le", "le", "gt", "ge"]: | ||
with pytest.raises(ValueError, match=msg): | ||
|
@@ -553,68 +551,83 @@ def test_comparison_tuples(self): | |
expected = Series([True, False]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_comparison_operators_with_nas(self): | ||
@pytest.mark.parametrize("op", ["lt", "le", "gt", "ge", "eq", "ne"]) | ||
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. I think these exist as dunder strings in the |
||
def test_comparison_operators_with_nas(self, op): | ||
ser = Series(bdate_range("1/1/2000", periods=10), dtype=object) | ||
ser[::2] = np.nan | ||
|
||
# test that comparisons work | ||
ops = ["lt", "le", "gt", "ge", "eq", "ne"] | ||
for op in ops: | ||
val = ser[5] | ||
val = ser[5] | ||
|
||
f = getattr(operator, op) | ||
result = f(ser, val) | ||
f = getattr(operator, op) | ||
result = f(ser, val) | ||
|
||
expected = f(ser.dropna(), val).reindex(ser.index) | ||
expected = f(ser.dropna(), val).reindex(ser.index) | ||
|
||
if op == "ne": | ||
expected = expected.fillna(True).astype(bool) | ||
else: | ||
expected = expected.fillna(False).astype(bool) | ||
if op == "ne": | ||
expected = expected.fillna(True).astype(bool) | ||
else: | ||
expected = expected.fillna(False).astype(bool) | ||
|
||
tm.assert_series_equal(result, expected) | ||
tm.assert_series_equal(result, expected) | ||
|
||
# FIXME: dont leave commented-out | ||
# fffffffuuuuuuuuuuuu | ||
# result = f(val, s) | ||
# expected = f(val, s.dropna()).reindex(s.index) | ||
# tm.assert_series_equal(result, expected) | ||
# FIXME: dont leave commented-out | ||
# result = f(val, s) | ||
# expected = f(val, s.dropna()).reindex(s.index) | ||
# tm.assert_series_equal(result, expected) | ||
|
||
def test_ne(self): | ||
ts = Series([3, 4, 5, 6, 7], [3, 4, 5, 6, 7], dtype=float) | ||
expected = [True, True, False, True, True] | ||
assert tm.equalContents(ts.index != 5, expected) | ||
assert tm.equalContents(~(ts.index == 5), expected) | ||
|
||
def test_comp_ops_df_compat(self): | ||
@pytest.mark.parametrize( | ||
"left, right", | ||
[ | ||
( | ||
pd.Series([1, 2, 3], index=list("ABC"), name="x"), | ||
pd.Series([2, 2, 2], index=list("ABD"), name="x"), | ||
), | ||
( | ||
pd.Series([1, 2, 3], index=list("ABC"), name="x"), | ||
pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x"), | ||
), | ||
], | ||
) | ||
def test_comp_ops_df_compat(self, left, right): | ||
# GH 1134 | ||
s1 = pd.Series([1, 2, 3], index=list("ABC"), name="x") | ||
s2 = pd.Series([2, 2, 2], index=list("ABD"), name="x") | ||
|
||
s3 = pd.Series([1, 2, 3], index=list("ABC"), name="x") | ||
s4 = pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x") | ||
|
||
for left, right in [(s1, s2), (s2, s1), (s3, s4), (s4, s3)]: | ||
|
||
msg = "Can only compare identically-labeled Series objects" | ||
with pytest.raises(ValueError, match=msg): | ||
left == right | ||
msg = "Can only compare identically-labeled Series objects" | ||
with pytest.raises(ValueError, match=msg): | ||
left == right | ||
with pytest.raises(ValueError, match=msg): | ||
right == left | ||
|
||
with pytest.raises(ValueError, match=msg): | ||
left != right | ||
with pytest.raises(ValueError, match=msg): | ||
left != right | ||
with pytest.raises(ValueError, match=msg): | ||
right != left | ||
|
||
with pytest.raises(ValueError, match=msg): | ||
left < right | ||
with pytest.raises(ValueError, match=msg): | ||
left < right | ||
with pytest.raises(ValueError, match=msg): | ||
right < left | ||
|
||
msg = "Can only compare identically-labeled DataFrame objects" | ||
with pytest.raises(ValueError, match=msg): | ||
left.to_frame() == right.to_frame() | ||
msg = "Can only compare identically-labeled DataFrame objects" | ||
with pytest.raises(ValueError, match=msg): | ||
left.to_frame() == right.to_frame() | ||
with pytest.raises(ValueError, match=msg): | ||
right.to_frame() == left.to_frame() | ||
|
||
with pytest.raises(ValueError, match=msg): | ||
left.to_frame() != right.to_frame() | ||
with pytest.raises(ValueError, match=msg): | ||
left.to_frame() != right.to_frame() | ||
with pytest.raises(ValueError, match=msg): | ||
right.to_frame() != left.to_frame() | ||
|
||
with pytest.raises(ValueError, match=msg): | ||
left.to_frame() < right.to_frame() | ||
with pytest.raises(ValueError, match=msg): | ||
left.to_frame() < right.to_frame() | ||
with pytest.raises(ValueError, match=msg): | ||
right.to_frame() < left.to_frame() | ||
|
||
def test_compare_series_interval_keyword(self): | ||
# GH#25338 | ||
|
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.
could parameterize here (might have to split the test)