-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.loc not aligning dict when setting to a column #47361
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
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.
Nice find that this already works on the multiblock case.
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.
lgtm; cc @jreback
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.
lgtm, minor comment
@@ -4709,6 +4709,8 @@ def _sanitize_column(self, value) -> ArrayLike: | |||
# We should never get here with DataFrame value | |||
if isinstance(value, Series): | |||
return _reindex_for_setitem(value, self.index) | |||
elif isinstance(value, dict): |
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.
is_dict_like ?
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.
I aligned this with a codepath in indexing.py
if (isinstance(value, ABCSeries) and name != "iloc") or isinstance(value, dict):
from pandas import Series
value = self._align_series(indexer, Series(value))
Not sure why we are calling for dict here, but should update in both places when we use is_dict_like here?
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.
is_dict_like
returns True for Series
, so it depends if the name != "iloc"
is supposed to exclude a specific Series case?
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.
Ah good point. Yes iloc should not align, hence the condition
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.
Looks like we end up there with a DataFrame, which raises. Will investigate in follow up how this happens
# Conflicts: # doc/source/whatsnew/v1.5.0.rst
This reverts commit d270851.
Thanks @phofl |
…-dev#47361) * BUG: DataFrame.loc not aligning dict when setting to a column * Add partial case * Use is_dict_like * Revert "Use is_dict_like" This reverts commit d270851.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.