-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
Fix Series v Index bool ops #22173
Merged
Merged
Fix Series v Index bool ops #22173
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b0ab1a4
Fix Series bool ops with Index
jbrockmendel d2d1564
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 69fc8d9
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel f043342
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 924ecde
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 58cd628
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 5f48482
comments, parametrize test
jbrockmendel bb54b5e
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 523eb04
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 17668a0
Merge tests
jbrockmendel 44aa551
Merge branch 'master' of https://github.com/pandas-dev/pandas into se…
jbrockmendel 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 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 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 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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
NaT, date_range, timedelta_range, Categorical) | ||
from pandas.core.indexes.datetimes import Timestamp | ||
import pandas.core.nanops as nanops | ||
from pandas.core import ops | ||
|
||
from pandas.compat import range | ||
from pandas import compat | ||
|
@@ -425,30 +426,6 @@ 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_logical_ops_with_index(self): | ||
# GH22092 | ||
ser = Series([True, True, False, False]) | ||
idx1 = Index([True, False, True, False]) | ||
idx2 = Index([1, 0, 1, 0]) | ||
|
||
expected = Series([True, False, False, False]) | ||
result1 = ser & idx1 | ||
assert_series_equal(result1, expected) | ||
result2 = ser & idx2 | ||
assert_series_equal(result2, expected) | ||
|
||
expected = Series([True, True, True, False]) | ||
result1 = ser | idx1 | ||
assert_series_equal(result1, expected) | ||
result2 = ser | idx2 | ||
assert_series_equal(result2, expected) | ||
|
||
expected = Series([False, True, True, False]) | ||
result1 = ser ^ idx1 | ||
assert_series_equal(result1, expected) | ||
result2 = ser ^ idx2 | ||
assert_series_equal(result2, 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] | ||
|
@@ -627,6 +604,42 @@ def test_ops_datetimelike_align(self): | |
result = (dt2.to_frame() - dt.to_frame())[0] | ||
assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize('op', [ | ||
operator.and_, | ||
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. pls add these as a fixture in conftest (follow-on PR) |
||
operator.or_, | ||
operator.xor, | ||
pytest.param(ops.rand_, | ||
marks=pytest.mark.xfail(reason="GH#22092 Index " | ||
"implementation returns " | ||
"Index", | ||
raises=AssertionError, | ||
strict=True)), | ||
pytest.param(ops.ror_, | ||
marks=pytest.mark.xfail(reason="GH#22092 Index " | ||
"implementation raises", | ||
raises=ValueError, strict=True)), | ||
pytest.param(ops.rxor, | ||
marks=pytest.mark.xfail(reason="GH#22092 Index " | ||
"implementation raises", | ||
raises=TypeError, strict=True)) | ||
]) | ||
def test_bool_ops_with_index(self, op): | ||
# GH#22092, GH#19792 | ||
ser = Series([True, True, False, False]) | ||
idx1 = Index([True, False, True, False]) | ||
idx2 = Index([1, 0, 1, 0]) | ||
|
||
expected = Series([op(ser[n], idx1[n]) for n in range(len(ser))]) | ||
|
||
result = op(ser, idx1) | ||
assert_series_equal(result, expected) | ||
|
||
expected = Series([op(ser[n], idx2[n]) for n in range(len(ser))], | ||
dtype=bool) | ||
|
||
result = op(ser, idx2) | ||
assert_series_equal(result, expected) | ||
|
||
def test_operators_bitwise(self): | ||
# GH 9016: support bitwise op for integer types | ||
index = list('bca') | ||
|
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.
From an error reporting perspective, I might go for:
A bare assert statement would unfortunately not provide much info to the end-user (admittedly, my proposed change assumes that the
TypeError
raised has some kind of message). At the very least, adding an error message on theassert
would be useful.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.
This comment BTW applies to any of your other
assert
statements.