-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
ENH: Enable indexing with nullable Boolean #31591
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 11 commits
75c915f
9c5b9f0
2441b40
d71d1ba
4d3a264
543ef9a
d3e7a69
ad7ae66
6991394
f6e9ce5
1234407
9b7e879
efdd29a
7fa36b6
b8e3d6b
bc3fe3f
73ad221
547d7bc
5649445
bb3d143
f107252
7b924b7
46d77df
ac71cbf
e5ed092
9fcdb23
c2dfa93
a9a12b1
7c10f33
cf3d60d
157d8b9
250f228
647f0f6
6ccd96d
a9e73de
adc3075
29ff823
0a58605
b38a209
5088cbb
54efdd9
c6b81ed
67800c6
4c334f3
578fd3c
a559385
705947e
4974778
319b525
8007ce4
a10765f
d7fc3b7
bca582e
6f9a298
e1e39fe
5a72b2f
c0e8dc7
a293bc6
607d9ed
2e7f9b3
bfe472b
a6294f8
c6d23f6
c8ee434
fbda99d
3bf9327
dd65b0d
974ec5d
8f2d7bb
080d1d2
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 |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
from pandas.util._decorators import Appender | ||
|
||
from pandas.core.dtypes.common import ( | ||
is_bool_dtype, | ||
is_extension_array_dtype, | ||
is_float, | ||
is_integer, | ||
is_iterator, | ||
|
@@ -2222,6 +2224,12 @@ def check_bool_indexer(index: Index, key) -> np.ndarray: | |
"the indexed object do not match)." | ||
) | ||
result = result.astype(bool)._values | ||
elif is_extension_array_dtype(key) and is_bool_dtype(key): | ||
|
||
mask = isna(key) | ||
dsaxton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if mask.any(): | ||
result = np.asarray(key.fillna(False), dtype=bool) | ||
else: | ||
result = np.asarray(key, dtype=bool) | ||
else: | ||
# key might be sparse / object-dtype bool, check_array_indexer needs bool array | ||
|
||
result = np.asarray(result, dtype=bool) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -929,3 +929,23 @@ def test_diff(): | |
result = s.diff() | ||
expected = pd.Series(expected) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
def test_nullable_boolean_mask_series(): | ||
|
||
s = pd.Series([1, 2, 3]) | ||
mask = pd.array([True, True, None], dtype="boolean") | ||
|
||
result = s[mask] | ||
expected = s.iloc[:2] | ||
|
||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
def test_nullable_boolean_mask_frame(): | ||
df = pd.DataFrame({"a": [1, 2, 3]}) | ||
mask = pd.array([True, True, None], dtype="boolean") | ||
|
||
result = df[mask] | ||
expected = df.iloc[:2, :] | ||
|
||
tm.assert_frame_equal(result, expected) |
Uh oh!
There was an error while loading. Please reload this page.