-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix regression in loc setitem raising KeyError when enlarging df with multiindex #39161
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
pandas/core/indexing.py
Outdated
if isinstance(key, tuple) and not isinstance(self.obj.index, ABCMultiIndex): | ||
if isinstance(key, tuple) and ( | ||
isinstance(key[0], slice) or not isinstance(self.obj.index, ABCMultiIndex) | ||
): | ||
# key may be a tuple if we are .loc | ||
# if index is not a MultiIndex, set key to column part |
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.
Thanks @phofl for the PR. does this comment need updating?
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.
Thx
pandas/core/indexing.py
Outdated
@@ -662,7 +662,9 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None): | |||
if self.ndim != 2: | |||
return | |||
|
|||
if isinstance(key, tuple) and not isinstance(self.obj.index, ABCMultiIndex): | |||
if isinstance(key, tuple) and ( |
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 we need len(key) as a 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.
wow this is a specific condition (i know i asked you to update). umm anyway we can be more general 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.
Yeah, was not happy with that either. This is better and does the job now.
thanks @phofl |
@meeseeksdev backport 1.2.x |
…eyError when enlarging df with multiindex
…en enlarging df with multiindex (#39187) Co-authored-by: patrick <[email protected]>
The previous fix only viewed row indexers not column indexers