-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: separate bloated test #28081
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
REF: separate bloated test #28081
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -36,22 +36,14 @@ def test_bool_operators_with_nas(self, bool_op): | |
expected[mask] = False | ||
assert_series_equal(result, expected) | ||
|
||
def test_operators_bitwise(self): | ||
def test_logical_operators_bool_dtype_with_empty(self): | ||
# GH#9016: support bitwise op for integer types | ||
index = list("bca") | ||
|
||
s_tft = Series([True, False, True], index=index) | ||
s_fff = Series([False, False, False], index=index) | ||
s_tff = Series([True, False, False], index=index) | ||
s_empty = Series([]) | ||
|
||
# TODO: unused | ||
# s_0101 = Series([0, 1, 0, 1]) | ||
|
||
s_0123 = Series(range(4), dtype="int64") | ||
s_3333 = Series([3] * 4) | ||
s_4444 = Series([4] * 4) | ||
|
||
res = s_tft & s_empty | ||
expected = s_fff | ||
assert_series_equal(res, expected) | ||
|
@@ -60,6 +52,16 @@ def test_operators_bitwise(self): | |
expected = s_tft | ||
assert_series_equal(res, expected) | ||
|
||
def test_logical_operators_int_dtype_with_int_dtype(self): | ||
# GH#9016: support bitwise op for integer types | ||
|
||
# TODO: unused | ||
# s_0101 = Series([0, 1, 0, 1]) | ||
|
||
s_0123 = Series(range(4), dtype="int64") | ||
s_3333 = Series([3] * 4) | ||
s_4444 = Series([4] * 4) | ||
|
||
res = s_0123 & s_3333 | ||
expected = Series(range(4), dtype="int64") | ||
assert_series_equal(res, expected) | ||
|
@@ -68,76 +70,129 @@ def test_operators_bitwise(self): | |
expected = Series(range(4, 8), dtype="int64") | ||
assert_series_equal(res, expected) | ||
|
||
s_a0b1c0 = Series([1], list("b")) | ||
|
||
res = s_tft & s_a0b1c0 | ||
expected = s_tff.reindex(list("abc")) | ||
s_1111 = Series([1] * 4, dtype="int8") | ||
res = s_0123 & s_1111 | ||
expected = Series([0, 1, 0, 1], dtype="int64") | ||
assert_series_equal(res, expected) | ||
|
||
res = s_tft | s_a0b1c0 | ||
expected = s_tft.reindex(list("abc")) | ||
res = s_0123.astype(np.int16) | s_1111.astype(np.int32) | ||
expected = Series([1, 1, 3, 3], dtype="int32") | ||
assert_series_equal(res, expected) | ||
|
||
n0 = 0 | ||
res = s_tft & n0 | ||
expected = s_fff | ||
assert_series_equal(res, expected) | ||
def test_logical_operators_int_dtype_with_int_scalar(self): | ||
# GH#9016: support bitwise op for integer types | ||
s_0123 = Series(range(4), dtype="int64") | ||
|
||
res = s_0123 & n0 | ||
res = s_0123 & 0 | ||
expected = Series([0] * 4) | ||
assert_series_equal(res, expected) | ||
|
||
n1 = 1 | ||
res = s_tft & n1 | ||
expected = s_tft | ||
assert_series_equal(res, expected) | ||
|
||
res = s_0123 & n1 | ||
res = s_0123 & 1 | ||
expected = Series([0, 1, 0, 1]) | ||
assert_series_equal(res, expected) | ||
|
||
s_1111 = Series([1] * 4, dtype="int8") | ||
res = s_0123 & s_1111 | ||
expected = Series([0, 1, 0, 1], dtype="int64") | ||
assert_series_equal(res, expected) | ||
|
||
res = s_0123.astype(np.int16) | s_1111.astype(np.int32) | ||
expected = Series([1, 1, 3, 3], dtype="int32") | ||
assert_series_equal(res, expected) | ||
def test_logical_operators_int_dtype_with_float(self): | ||
# GH#9016: support bitwise op for integer types | ||
s_0123 = Series(range(4), dtype="int64") | ||
|
||
with pytest.raises(TypeError): | ||
s_1111 & "a" | ||
with pytest.raises(TypeError): | ||
s_1111 & ["a", "b", "c", "d"] | ||
with pytest.raises(TypeError): | ||
s_0123 & np.NaN | ||
with pytest.raises(TypeError): | ||
s_0123 & 3.14 | ||
with pytest.raises(TypeError): | ||
s_0123 & [0.1, 4, 3.14, 2] | ||
with pytest.raises(TypeError): | ||
s_0123 & np.array([0.1, 4, 3.14, 2]) | ||
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. this assertion is the only new one, everything else is just moved around |
||
|
||
# s_0123 will be all false now because of reindexing like s_tft | ||
exp = Series([False] * 7, index=[0, 1, 2, 3, "a", "b", "c"]) | ||
assert_series_equal(s_tft & s_0123, exp) | ||
|
||
# s_tft will be all false now because of reindexing like s_0123 | ||
exp = Series([False] * 7, index=[0, 1, 2, 3, "a", "b", "c"]) | ||
assert_series_equal(s_0123 & s_tft, exp) | ||
|
||
assert_series_equal(s_0123 & False, Series([False] * 4)) | ||
assert_series_equal(s_0123 ^ False, Series([False, True, True, True])) | ||
assert_series_equal(s_0123 & [False], Series([False] * 4)) | ||
assert_series_equal(s_0123 & (False), Series([False] * 4)) | ||
assert_series_equal( | ||
s_0123 & Series([False, np.NaN, False, False]), Series([False] * 4) | ||
) | ||
# FIXME: this should be consistent with the list case above | ||
expected = Series([False, True, False, True]) | ||
result = s_0123 & Series([0.1, 4, -3.14, 2]) | ||
assert_series_equal(result, expected) | ||
|
||
def test_logical_operators_int_dtype_with_str(self): | ||
s_1111 = Series([1] * 4, dtype="int8") | ||
|
||
with pytest.raises(TypeError): | ||
s_1111 & "a" | ||
with pytest.raises(TypeError): | ||
s_1111 & ["a", "b", "c", "d"] | ||
|
||
def test_logical_operators_int_dtype_with_bool(self): | ||
# GH#9016: support bitwise op for integer types | ||
s_0123 = Series(range(4), dtype="int64") | ||
|
||
expected = Series([False] * 4) | ||
|
||
result = s_0123 & False | ||
assert_series_equal(result, expected) | ||
|
||
result = s_0123 & [False] | ||
assert_series_equal(result, expected) | ||
|
||
result = s_0123 & (False,) | ||
assert_series_equal(result, expected) | ||
|
||
s_ftft = Series([False, True, False, True]) | ||
assert_series_equal(s_0123 & Series([0.1, 4, -3.14, 2]), s_ftft) | ||
result = s_0123 ^ False | ||
expected = Series([False, True, True, True]) | ||
assert_series_equal(result, expected) | ||
|
||
def test_logical_operators_int_dtype_with_object(self): | ||
# GH#9016: support bitwise op for integer types | ||
s_0123 = Series(range(4), dtype="int64") | ||
|
||
result = s_0123 & Series([False, np.NaN, False, False]) | ||
expected = Series([False] * 4) | ||
assert_series_equal(result, expected) | ||
|
||
s_abNd = Series(["a", "b", np.NaN, "d"]) | ||
res = s_0123 & s_abNd | ||
expected = s_ftft | ||
result = s_0123 & s_abNd | ||
expected = Series([False, True, False, True]) | ||
assert_series_equal(result, expected) | ||
|
||
def test_logical_operators_bool_dtype_with_int(self): | ||
index = list("bca") | ||
|
||
s_tft = Series([True, False, True], index=index) | ||
s_fff = Series([False, False, False], index=index) | ||
|
||
res = s_tft & 0 | ||
expected = s_fff | ||
assert_series_equal(res, expected) | ||
|
||
res = s_tft & 1 | ||
expected = s_tft | ||
assert_series_equal(res, expected) | ||
|
||
def test_logical_operators_int_dtype_with_bool_dtype_and_reindex(self): | ||
# GH#9016: support bitwise op for integer types | ||
|
||
# with non-matching indexes, logical operators will cast to object | ||
# before operating | ||
index = list("bca") | ||
|
||
s_tft = Series([True, False, True], index=index) | ||
s_tft = Series([True, False, True], index=index) | ||
s_tff = Series([True, False, False], index=index) | ||
|
||
s_0123 = Series(range(4), dtype="int64") | ||
|
||
# s_0123 will be all false now because of reindexing like s_tft | ||
expected = Series([False] * 7, index=[0, 1, 2, 3, "a", "b", "c"]) | ||
result = s_tft & s_0123 | ||
assert_series_equal(result, expected) | ||
|
||
expected = Series([False] * 7, index=[0, 1, 2, 3, "a", "b", "c"]) | ||
result = s_0123 & s_tft | ||
assert_series_equal(result, expected) | ||
|
||
s_a0b1c0 = Series([1], list("b")) | ||
|
||
res = s_tft & s_a0b1c0 | ||
expected = s_tff.reindex(list("abc")) | ||
assert_series_equal(res, expected) | ||
|
||
res = s_tft | s_a0b1c0 | ||
expected = s_tft.reindex(list("abc")) | ||
assert_series_equal(res, expected) | ||
|
||
def test_scalar_na_logical_ops_corners(self): | ||
|
@@ -523,6 +578,7 @@ def test_comparison_operators_with_nas(self): | |
|
||
assert_series_equal(result, expected) | ||
|
||
# FIXME: dont leave commented-out | ||
# fffffffuuuuuuuuuuuu | ||
# result = f(val, s) | ||
# expected = f(val, s.dropna()).reindex(s.index) | ||
|
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.
What are the code changes here required for? Separate from the actual test split?
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.
The goal is to isolate Series-specific parts of the function from EA/ndarray parts (see also _arith_method_SERIES and _comp_method_SERIES in #28066).
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.
Is there a way to move the tests without making code changes? I'm admittedly not very well versed with this code so I might be missing something simple, but I think test and code changes as separate PRs is a safer approach
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.
That's basically the idea of this PR. This is technically a code change, but it is about as benign as they come