Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bb904cb
ENH: add BooleanArray extension array (#29555)
jorisvandenbossche Nov 25, 2019
13c7ea3
move
TomAugspurger Nov 26, 2019
fff786f
doc fixup
TomAugspurger Nov 26, 2019
4067e7f
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Nov 26, 2019
708c553
working
TomAugspurger Nov 26, 2019
c56894e
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Nov 27, 2019
2e9d547
updates
TomAugspurger Nov 27, 2019
373aaab
updates
TomAugspurger Nov 27, 2019
7f78a64
Raise for NaN
TomAugspurger Nov 27, 2019
36b171b
added tests for empty
TomAugspurger Nov 27, 2019
747e046
added tests for inplace mutation
TomAugspurger Nov 27, 2019
d0a8cca
Do not assume masked values are False
TomAugspurger Nov 27, 2019
fe061b0
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Nov 27, 2019
9f9e44c
mypy
TomAugspurger Nov 27, 2019
0a34257
doc fixups
TomAugspurger Nov 27, 2019
2ba0034
Added benchmarks
TomAugspurger Nov 27, 2019
2d1129a
update tests
TomAugspurger Nov 27, 2019
a24fc22
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Nov 27, 2019
77dd1fc
remove unneded setitem
TomAugspurger Nov 27, 2019
7b9002c
optimize
TomAugspurger Nov 27, 2019
c18046b
comments
TomAugspurger Nov 27, 2019
1237caa
just do the xor
TomAugspurger Nov 27, 2019
2ecf9b8
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Dec 2, 2019
87aeb09
fixup docstring
TomAugspurger Dec 2, 2019
969b6dc
fix label
TomAugspurger Dec 2, 2019
1c9ba49
PERF: faster or
TomAugspurger Dec 2, 2019
8eec954
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Dec 4, 2019
cb47b6a
handle pd.NA
TomAugspurger Dec 4, 2019
2a946b9
validate
TomAugspurger Dec 4, 2019
efb6f8b
please mypy
TomAugspurger Dec 4, 2019
004238e
move to nanops
TomAugspurger Dec 4, 2019
5a2c81c
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Dec 5, 2019
7032318
move
TomAugspurger Dec 5, 2019
bbb7f9b
numpy scalars
TomAugspurger Dec 5, 2019
ce763b4
doc note
TomAugspurger Dec 5, 2019
5bc5328
handle numpy bool
TomAugspurger Dec 5, 2019
457bd08
Merge remote-tracking branch 'upstream/master' into boolean-array-kleene
TomAugspurger Dec 6, 2019
31c2bc6
cleanup
TomAugspurger Dec 6, 2019
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
Prev Previous commit
Next Next commit
validate
  • Loading branch information
TomAugspurger committed Dec 4, 2019
commit 2a946b9f7d570cb27b00599db9e8bd7cc60f4a3d
7 changes: 7 additions & 0 deletions pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ def logical_method(self, other):
)
other, mask = coerce_to_array(other, copy=False)

if other_is_scalar and not isinstance(other, (type(libmissing.NA), bool)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add np.bool_ as well I think (and tests for this), as a numpy scalar is not an instance of a bool:

In [14]: isinstance(np.bool_(True), bool) Out[14]: False 
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, other is pd.NA or isinstance(other, bool) is a bit faster, although I am not sure we care about the 60 ns difference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but I see that you actually already have a test for numpy scalars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was tripped up by np.bool vs np.bool_.

raise TypeError(
"'other' should be pandas.NA or a bool. Got {} instead".format(
type(other).__name__
)
)

if not other_is_scalar and len(self) != len(other):
raise ValueError("Lengths must match to compare")

Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/arrays/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ def test_ufunc_reduce_raises(values):


class TestLogicalOps(BaseOpsUtil):
def test_numpy_scalars_ok(self, all_logical_operators):
a = pd.array([True, False, None], dtype="boolean")
op = getattr(a, all_logical_operators)

tm.assert_extension_array_equal(op(True), op(np.bool(True)))
tm.assert_extension_array_equal(op(False), op(np.bool(False)))

def get_op_from_name(self, op_name):
short_opname = op_name.strip("_")
short_opname = short_opname if "xor" in short_opname else short_opname + "_"
Expand Down Expand Up @@ -403,6 +410,12 @@ def test_logical_nan_raises(self, all_logical_operators):
with pytest.raises(ValueError, match=msg):
getattr(a, op_name)(np.nan)

@pytest.mark.parametrize("other", ["a", 1])
def test_non_bool_or_na_other_raises(self, other, all_logical_operators):
a = pd.array([True, False], dtype="boolean")
with pytest.raises(TypeError, match=str(type(other).__name__)):
getattr(a, all_logical_operators)(other)

def test_kleene_or(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A careful review of these new test cases would be greatly appreciated. I've tried to make them as clear as possible, while covering all the cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the tests, very clear, added a few comments, for the rest looks good to me!

# A clear test of behavior.
a = pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
Expand Down