-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: df.iloc not working with NamedTuple #57004
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
Sorry, I don't understand. In particular, the test you highlighted passes with this patch applied and from your comment above I expected it not to. |
I mean if we only change Because in this test, namedtuples are elements of the index, and are used as labels in pandas/pandas/core/indexing.py Lines 1180 to 1192 in 7281475
|
Thanks - makes sense. I think this might need further discussion in that case. I do not see a way to support tuple (and subclasses of tuple) in a flat Index (i.e. not a MultiIndex) and using tuples for accessing (row, column) pairs. Indeed, the following variant of that test using tuples fails on main:
The only way I can see making it all work is to try one and if it fails try the other - which I think we want to avoid. While we don't run into this problem with iloc, I wonder if we want to avoid supporting subclasses with iloc but not loc. |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
.iloc
fails #48188(Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.@rhshadrach I kept the
type(key) is tuple
since index can contain namedtuple, used as key indf.loc[key]
, as shown in the test case below:pandas/pandas/tests/indexing/test_loc.py
Lines 1615 to 1624 in 488f6bd