-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: loc.setitem corner case #37931
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
BUG: loc.setitem corner case #37931
Conversation
if len(value) == 1 and not is_integer(info_axis): | ||
# This is a case like df.iloc[:3, [1]] = [0] | ||
# where we treat as df.iloc[:3, 1] = 0 | ||
return self._setitem_with_indexer((pi, info_axis[0]), value[0]) |
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 reason for not using _setitem_single_column
? Seems to work when trying out locally. LGTM otherwise
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.
either way works. this seemed like a more obvious "we are reducing this to a simpler case" representation
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.
Ok, this is fine with me then.
@@ -210,6 +210,11 @@ def test_multiindex_assignment(self): | |||
with pytest.raises(ValueError, match=msg): | |||
df.loc[4, "c"] = [0] | |||
|
|||
# But with a length-1 listlike column indexer this works | |||
df.loc[4, ["c"]] = [0] |
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.
what happens with this case now?
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.
behaves like df.loc[4, "c"] = 0
, just edited the comment to make that clear
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.
also merge master
rebased+green |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
cc @phofl if you've got any thoughts on how to handle this case