-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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 8 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 |
---|---|---|
|
@@ -98,8 +98,9 @@ def test_setitem_iloc_scalar_multiple_homogoneous(self, data): | |
[ | ||
np.array([True, True, True, False, False]), | ||
pd.array([True, True, True, False, False], dtype="boolean"), | ||
pd.array([True, True, True, pd.NA, pd.NA], dtype="boolean"), | ||
], | ||
ids=["numpy-array", "boolean-array"], | ||
ids=["numpy-array", "boolean-array", "boolean-array-na"], | ||
) | ||
def test_setitem_mask(self, data, mask, box_in_series): | ||
arr = data[:5].copy() | ||
|
@@ -124,20 +125,17 @@ def test_setitem_mask_raises(self, data, box_in_series): | |
with pytest.raises(IndexError, match="wrong length"): | ||
data[mask] = data[0] | ||
|
||
def test_setitem_mask_boolean_array_raises(self, data, box_in_series): | ||
# missing values in mask | ||
def test_setitem_mask_boolean_array_with_na(self, data, box_in_series): | ||
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. Isn't this test duplicating the 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. Somewhat, yes 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. You can simply remove it then, I think? |
||
mask = pd.array(np.zeros(data.shape, dtype="bool"), dtype="boolean") | ||
mask[:2] = pd.NA | ||
mask[:3] = True | ||
mask[3:5] = pd.NA | ||
|
||
if box_in_series: | ||
data = pd.Series(data) | ||
|
||
msg = ( | ||
"Cannot mask with a boolean indexer containing NA values|" | ||
"cannot mask with array containing NA / NaN values" | ||
) | ||
with pytest.raises(ValueError, match=msg): | ||
data[mask] = data[0] | ||
data[mask] = data[0] | ||
|
||
assert (data[:3] == data[0]).all() | ||
|
||
@pytest.mark.parametrize( | ||
"idx", | ||
|
@@ -219,36 +217,6 @@ def test_setitem_mask_broadcast(self, data, setter): | |
assert ser[0] == data[10] | ||
assert ser[1] == data[10] | ||
|
||
def test_setitem_boolean_na_mask(self, data, box_in_series): | ||
# https://github.com/pandas-dev/pandas/issues/31503 | ||
if box_in_series: | ||
data = pd.Series(data) | ||
|
||
mask = pd.array(np.zeros(len(data), dtype=bool), dtype="boolean") | ||
mask[:2] = pd.NA | ||
mask[2:4] = True | ||
original = data.copy() | ||
|
||
data[mask] = data[mask.fillna(False)] | ||
|
||
if box_in_series: | ||
tm.assert_series_equal(data, original) | ||
else: | ||
tm.assert_extension_array_equal(data, original) | ||
|
||
def test_setitem_boolean_na_mask_frame(self, data): | ||
# https://github.com/pandas-dev/pandas/issues/31503 | ||
df = pd.DataFrame({"a": range(len(data)), "b": data}) | ||
original = df.copy() | ||
|
||
mask = pd.array(np.zeros(len(data), dtype=bool), dtype="boolean") | ||
mask[:2] = pd.NA | ||
mask[2:4] = True | ||
|
||
df.loc[mask, "b"] = data[mask.fillna(False)] | ||
|
||
tm.assert_frame_equal(df, original) | ||
|
||
def test_setitem_expand_columns(self, data): | ||
df = pd.DataFrame({"A": data}) | ||
result = df.copy() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,10 +415,6 @@ def test_setitem_mask(self, data, mask, box_in_series): | |
def test_setitem_mask_raises(self, data, box_in_series): | ||
super().test_setitem_mask_raises(data, box_in_series) | ||
|
||
@skip_nested | ||
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. do we have a setitem 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. Yes, I added a case containing NA to the the |
||
def test_setitem_mask_boolean_array_raises(self, data, box_in_series): | ||
super().test_setitem_mask_boolean_array_raises(data, box_in_series) | ||
|
||
@skip_nested | ||
@pytest.mark.parametrize( | ||
"idx", | ||
|
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.
rather than remove this can you turn it into a test (obviously changed that we no longer raise)