Skip to content

BUG: Setting values on DataFrame with multi-index .loc(axis=0) access adds columns #58301

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

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

eshaready
Copy link
Contributor

@eshaready eshaready commented Apr 18, 2024

Setting values on a Multi-Index DataFrame with axis=0 passed into loc caused columns to be added when they shouldn't be.

This occurred because when setting items(s) with loc, the axis argument was ignored; _ensure_listlike_indexer(self, key, axis=None, value=None) never has self.axis passed in, and always sets axis to 1.

To solve this, we passed self.axis in as an argument when calling the function, and added an if statement to only set axis to 1 if none is specified.

coauthored with @regieleki !

@mroeschke mroeschke added the Indexing Related to indexing on series/frames, not to indexes themselves label Apr 18, 2024
@mroeschke mroeschke added this to the 3.0 milestone Apr 18, 2024
@mroeschke mroeschke merged commit f86f9f2 into pandas-dev:main Apr 18, 2024
46 checks passed
@mroeschke
Copy link
Member

Thanks @eshaready

@btschroer
Copy link

Thanks @eshaready!

pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
… adds columns (pandas-dev#58301)

* fixed the issue by making sure setting an item takes into account the axis argument if supplied to loc. added a test checking for this based on the github issue as well

* Running pre commit checks

* Pre commit checks

* Update doc/source/whatsnew/v3.0.0.rst

Co-authored-by: Matthew Roeschke <[email protected]>

---------

Co-authored-by: Matthew Roeschke <[email protected]>
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.

BUG: Setting values on DataFrame with multi-index .loc(axis=0) access adds columns
3 participants