-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Scalar assignment to empty dataframe with loc. Closes GH41891 #41921
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: Scalar assignment to empty dataframe with loc. Closes GH41891 #41921
Conversation
This weakens a check introduced in 7bbeb79 which caused ValueErrors for df[:, 1] = 1 if df is an empty DataFrame. With this commit no error is thrown and the column is added to the dataframe (which remains empty).
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 is the actual problem you are trying to solve?
adding a column with a value which disappears (not to mention not setting a dtype) is nonsensical and harmful not helpful
the issue you pointed is completely unrelated as there IS a non empty index
Thanks for taking a look at this so quickly @jreback .
My expectations for
Thus, if This is also the behaviour of
In my branch, the
Given a copy, I want to be able to set a scalar value without explicitly having to check for emptiness every time. So basically I'm looking for something that replicates the behavior of As written above, from my perspective it also feels very unnatural and unnecessary to have a |
I think this is quite confusing.
results in
while your example would result in an empty Frame. Assigning values to empty DataFrames itself and resulting in empty dfs is not ideal imo |
Your example is using the enlargement syntax, which is triggered whenever there's something list like on the right hand side (which I agree isn't entirely intuitive, especially because there's no index given for the new entry in your example). But I think it's even more confusing that The new behavior proposed here would be fairly backwards compatible and I'm still convinced that it would be an improvement. Sorry for being stubborn. |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
Thanks for the PR, but appears from the review that this current approach does not have much support from other members of the core team. I think it's probably best if this is further discussed in the original issue first before proceeding with a PR. Closing. |
This weakens a check introduced in 7bbeb79 in PR #5227 addressing issue #5226 ("New appending behavior doesn't work on an empty DataFrame") which caused ValueErrors for
df[:, 1] = 1
if df is an empty DataFrame. With this commit no error is thrown and the column is added to the dataframe (which remains empty).See #41891 for why this makes sense.