-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: DataFrame.__setitem__ raising ValueError when setting multiple values to dup columns #39280
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
…alues to dup columns
|
Hacky, will try to improve |
|
Hm this is a hacky edge case: This is tested in a unit test If this should work, we can't really implement because here is not clear what to do, interpret (1,2) as a column, which should result in (this is tested with the case above) or interpret as a row (as described in the op) which would result in The loc case interprets this as which results in an Error if len(index) != number of "a" in columns |
| self._set_item_frame_value(key, value) | ||
| elif is_list_like(value) and 1 < len( | ||
| self.columns.get_indexer_for([key]) | ||
| ) == len(value): |
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.
not necessarily for this PR, but it might be worth implementing a Index.count method (mirroring list.count)?
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.
Yeah this would be helpful probably, something like that would have helped in #39278
|
thanks @phofl |
|
Doesn't this slow down every setting operation with a single key? I think it's fine as a temporary measure, but really we shouldn't be doing multiple lookups for a single operation. |
Well no, I guess only with a list of keys. Still, we could check if |
|
That's probably a good idea, yes |
Setting with a scalar key which is duplicated in columns should be the same as using a listlike key