-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: consistency between logical ops & type casts #8151
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 all commits
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 |
---|---|---|
|
@@ -2368,6 +2368,31 @@ def check(series, other, check_reverse=False): | |
check(self.ts, 5, check_reverse=True) | ||
check(tm.makeFloatSeries(), tm.makeFloatSeries(), check_reverse=True) | ||
|
||
def test_bool_op(self): # GH6528 & GH8151 | ||
u = pd.Series([nan, nan, nan, False, False, True, True]) | ||
v = pd.Series([nan, False, True, False, True, False, True]) | ||
|
||
for a, b in [[u, v], [v, u]]: | ||
# against numpy logical casted to bool | ||
assert_series_equal(a | b, Series(np.logical_or(a, b), dtype='bool')) | ||
assert_series_equal(a & b, Series(np.logical_and(a, b), dtype='bool')) | ||
assert_series_equal(a ^ b, # np.logical_xor throws with floats! | ||
Series(np.logical_xor(a.values.astype(bool), | ||
b.values.astype(bool)))) | ||
|
||
assert_series_equal(~ a.astype(bool), | ||
Series(np.logical_not(a), dtype='bool')) | ||
|
||
# type cast semantics | ||
assert_series_equal(a | b, a.astype(bool) | b.astype(bool)) | ||
assert_series_equal(a & b, a.astype(bool) & b.astype(bool)) | ||
assert_series_equal(a ^ b, a.astype(bool) ^ b.astype(bool)) | ||
|
||
# symmetry | ||
assert_series_equal(a & b, b & a) | ||
assert_series_equal(a | b, b | a) | ||
assert_series_equal(a ^ b, b ^ a) | ||
|
||
def test_neg(self): | ||
assert_series_equal(-self.series, -1 * self.series) | ||
|
||
|
@@ -3418,7 +3443,7 @@ def test_comparison_label_based(self): | |
|
||
# identity | ||
# we would like s[s|e] == s to hold for any e, whether empty or not | ||
for e in [Series([]),Series([1],['z']),Series(['z']),Series(np.nan,b.index),Series(np.nan,a.index)]: | ||
for e in [Series([]),Series([1],['z']),Series(['z']),Series(False,b.index),Series(False,a.index)]: | ||
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 is a valid test 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. @jreback in python
in pandas:
this test passes only if same comment for the other test. |
||
result = a[a | e] | ||
assert_series_equal(result,a[a]) | ||
|
||
|
@@ -6144,4 +6169,3 @@ def test_unique_data_ownership(self): | |
if __name__ == '__main__': | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
exit=False) | ||
|
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.
don't change this test
you can add to but not change tests