-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: unclear what integer level name references: name or position? #21677
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
Comments
there are some issues that i believe this was discussed solution of course is to internally have a positional indexer only for most ops and convert s name to s positional (or raise / warm if duplicated or ambiguous from user code) |
OK, there is some "logic" in the above of course, which is: try "name", if that errors fall back to "positional" (similar as the logic in In any case this is not clearly documented in eg
We actually have an explicit test to cover the "name" case: pandas/pandas/tests/indexes/test_multi.py Lines 739 to 742 in 0b63e81
|
Yes, I also have that feeling, but couldn't directly find something
That is already what happens with |
I think #18872 (comment) is related |
Ideally, referring to a level with an integer should always give preference to positional interpretation, because it is unambiguous (e.g. duplicated names are not a problem). And I would avoid (at least in the long term) any kind of fallback. But doing this now will at least require a deprecation cycle. |
I discussed this a bit in #17123. |
I'd be interested in a resolution to this as well. In the library I'm working on, I've fallen back on refusing to accept DataFrames with integer names, to avoid the ambiguity, but that's not a great approach. |
I assumed that in eg
get_level_values
,stack
,unstack
, ... (which all boil down to the behaviour of_get_level_number
) using an integer to specify the level, would always mean positional because we have no way to disambiguate between position or name in those cases.But, this seems very inconsistent:
Am I missing something? Was this discussed before?
cc @toobaz
The text was updated successfully, but these errors were encountered: