-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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 6 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 |
---|---|---|
|
@@ -602,7 +602,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 com.is_bool_indexer(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. i haven't fully formed an opinion, but i think another alternative would be to properly handle boolean masks in Block.setitem. 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 are right, loc is not failing, this means we do not need this or. Removed it. Must have mixed something up before 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. Lists can be handled in Block.setitem already, but arrays from dtype object don't work. Lists are killed by the validation mentioned above in |
||
self._ensure_listlike_indexer(key) | ||
|
||
if self.axis is not None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1644,6 +1644,18 @@ def test_loc_setitem_mask_td64_series_value(self): | |
assert expected == result | ||
tm.assert_frame_equal(df, df_copy) | ||
|
||
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. can you parameterize the rhs by array as well as list 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. ahh i see the comment, but still think can parameterize. 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 |
||
# GH#20438 testing specifically list key, not arraylike | ||
ser = Series([0, 1, 2]) | ||
ser.loc[[True, False, True]] = [5, 10] | ||
expected = Series([5, 1, 10]) | ||
tm.assert_series_equal(ser, expected) | ||
|
||
df = DataFrame({"a": [0, 1, 2]}) | ||
df.loc[[True, False, True]] = [[5], [10]] | ||
expected = DataFrame({"a": [5, 1, 10]}) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
def test_series_loc_getitem_label_list_missing_values(): | ||
# gh-11428 | ||
|
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