Skip to content

BUG: DataFrame.__setitem__ raising ValueError with string indexer and empty df and df to set #38931

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 3 commits into from
Jan 6, 2021

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 3, 2021

Dont have to convert df to series, df has an index.
cc @jbrockmendel

@phofl phofl added the Indexing Related to indexing on series/frames, not to indexes themselves label Jan 3, 2021
# GH#38831
df = DataFrame(columns=["A", "B"])
other = DataFrame({"B": [1, 2]})
df[indexer] = other
Copy link
Member

Choose a reason for hiding this comment

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

do we need/want to check any of the other indexers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't know if this would be helpful, the string-DataFrame case is a special case while indexer in [list, Index, Series, array] is all the same (which was working previously)

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, can you check df.loc[:, indexer] ? should be the same result i think.

Copy link
Member Author

@phofl phofl Jan 5, 2021

Choose a reason for hiding this comment

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

No unfortunately not, in case of indexer=["B"] we align lhs and rhs, which leads to an empty result. This is losely related to our dicussion in #30439 @jbrockmendel

When indexer="B" this works as the case above

# GH#38831
df = DataFrame(columns=["A", "B"])
other = DataFrame({"B": [1, 2]})
df[indexer] = other
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, can you check df.loc[:, indexer] ? should be the same result i think.

@jreback jreback added this to the 1.3 milestone Jan 5, 2021
@jreback jreback added the Bug label Jan 5, 2021
@jreback jreback merged commit 9b16b1e into pandas-dev:master Jan 6, 2021
@phofl phofl deleted the 38831 branch January 6, 2021 01:13
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 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: frame_length_0[key] = nonempty_frame raises ValueError
3 participants