-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
… empty df and df to set
# GH#38831 | ||
df = DataFrame(columns=["A", "B"]) | ||
other = DataFrame({"B": [1, 2]}) | ||
df[indexer] = other |
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.
do we need/want to check any of the other indexers?
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.
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)
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.
hmm, can you check df.loc[:, indexer]
? should be the same result i think.
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.
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 |
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.
hmm, can you check df.loc[:, indexer]
? should be the same result i think.
� Conflicts: � doc/source/whatsnew/v1.3.0.rst
…d empty df and df to set (pandas-dev#38931)
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Dont have to convert df to series, df has an index.
cc @jbrockmendel