-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Bug in loc raised ValueError when setting value via boolean list #37761
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 4 commits
e38dc1c
e606f33
8e02de7
c8bacf5
64c3dfc
17c0cda
272f53b
e37d37c
9adcd05
0a45a73
29ec9b5
83745b1
7db17ce
a53ae1b
b5dd453
834c816
da88226
1293109
99a9330
0f9f515
08b0362
b971750
15ad761
c716b31
c5c15c9
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
from pandas.core.dtypes.common import ( | ||
is_array_like, | ||
is_bool_dtype, | ||
is_hashable, | ||
is_integer, | ||
is_iterator, | ||
|
@@ -602,7 +603,7 @@ def _get_setitem_indexer(self, key): | |
""" | ||
Convert a potentially-label-based key into a positional indexer. | ||
""" | ||
if self.name == "loc": | ||
if self.name == "loc" or is_bool_dtype(np.array(key)): | ||
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. is it only lists we want here, or would 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. That is better, changed it :) |
||
self._ensure_listlike_indexer(key) | ||
|
||
if self.axis is not None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1955,6 +1955,13 @@ def test_loc_setitem_dt64tz_values(self): | |
result = s2["a"] | ||
assert result == expected | ||
|
||
def test_loc_setitem_boolean_list(self): | ||
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. lets put this in TestLocBooleanMask can this be shared by DataFrame? few words after the GH ref to the effect of "specifically list key, not arraylike" 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. Done, added a |
||
# GH: 20438 | ||
ser = Series([0, 1, 2]) | ||
ser.loc[[True, False, True]] = [5, 10] | ||
expected = Series([5, 1, 10]) | ||
tm.assert_series_equal(ser, expected) | ||
|
||
|
||
@pytest.mark.parametrize("value", [1, 1.5]) | ||
def test_loc_int_in_object_index(frame_or_series, value): | ||
|
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.
is there a specific exception we can say instead of Error?
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.
ValueError, added it