-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Bug: Logical operator of Series with Index (#22092) #22293
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
Changes from 2 commits
2c1bb1a
3607834
9f7b586
fd0f381
f9f63fd
ba456e7
84ac158
aaf8349
d671f99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1383,7 +1383,7 @@ def na_op(x, y): | |
if isinstance(y, list): | ||
y = construct_1d_object_array_from_listlike(y) | ||
|
||
if isinstance(y, (np.ndarray, ABCSeries)): | ||
if isinstance(y, (np.ndarray, ABCSeries, ABCIndex)): | ||
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 should be ABCIndexClass, not ABCIndex. |
||
if (is_bool_dtype(x.dtype) and is_bool_dtype(y.dtype)): | ||
result = op(x, y) # when would this be hit? | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,6 +537,23 @@ def test_comparison_flex_alignment_fill(self): | |
exp = pd.Series([True, True, False, False], index=list('abcd')) | ||
assert_series_equal(left.gt(right, fill_value=0), exp) | ||
|
||
def test_comparison_with_index(self): | ||
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. can you check this on Int64Index as well. I think some other index types might work. 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. "comparison" is a misnomer here. Consider "binary_ops" or "logical_ops" |
||
# GH22092 | ||
ser = Series([True, True, False, False]) | ||
idx = Index([True, False, True, False]) | ||
|
||
expected = Series([True, False, False, False]) | ||
result = ser & idx | ||
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. cc @jbrockmendel I think we DO allow this on index types which don't makes sense, but we DO raise on Series, e.g. not sure what to make of [1] and [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.
Yah I've opened a couple of Issues about this. The existing Series ops don't handle dt64/td64 at all, and are not super-clear for some other dtypes. The reversed I don't think this PR fixes [4] (yet), needs to chance ABCIndex to ABCIndexClass (like #22173) 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. ok this is fine then (for now as you have other issues about this) |
||
assert_series_equal(result, expected) | ||
|
||
expected = Series([True, True, True, False]) | ||
result = ser | idx | ||
assert_series_equal(result, expected) | ||
|
||
expected = Series([False, True, True, False]) | ||
result = ser ^ idx | ||
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] | ||
|
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.
Describe the bug briefly. For an example, see #22173.