-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.at with non-unique axes #33047
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
Changes from 3 commits
8667c3a
3383a0d
42dfe29
6b044ca
02f6548
65aaa05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2063,7 +2063,17 @@ def _convert_key(self, key, is_setter: bool = False): | |
|
||
return key | ||
|
||
@property | ||
def _axes_are_unique(self) -> bool: | ||
# Only relevant for self.ndim == 2 | ||
assert self.ndim == 2 | ||
return self.obj.index.is_unique and self.obj.columns.is_unique | ||
|
||
def __getitem__(self, key): | ||
if self.ndim == 2 and not self._axes_are_unique: | ||
# GH#33041 fall back to .loc | ||
return self.obj.loc[key] | ||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One problem with this, though, is that it allows any kind of indexer for this case (not only scalar ones), and thus relaxing the requirements for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to address this issue |
||
|
||
if self.ndim != 1 or not is_scalar(key): | ||
# FIXME: is_scalar check is a kludge | ||
return super().__getitem__(key) | ||
|
@@ -2073,6 +2083,14 @@ def __getitem__(self, key): | |
loc = obj.index.get_loc(key) | ||
return obj.index._get_values_for_loc(obj, loc, key) | ||
|
||
def __setitem__(self, key, value): | ||
if self.ndim == 2 and not self._axes_are_unique: | ||
# GH#33041 fall back to .loc | ||
self.obj.loc[key] = value | ||
return | ||
|
||
return super().__setitem__(key, value) | ||
|
||
|
||
@doc(IndexingMixin.iat) | ||
class _iAtIndexer(_ScalarAccessIndexer): | ||
|
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.
can you add this assertion explicity
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.
updated+green