Skip to content
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

Merged
merged 3 commits into from
Nov 26, 2020
Merged

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

cc @phofl if you've got any thoughts on how to handle this case

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Nov 18, 2020
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])
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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]
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also merge master

@jbrockmendel
Copy link
Member Author

rebased+green

@jreback jreback added this to the 1.2 milestone Nov 26, 2020
@jreback jreback merged commit fe87624 into pandas-dev:master Nov 26, 2020
@jbrockmendel jbrockmendel deleted the bug-indexing-4 branch November 26, 2020 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants