Open Ynjxsjmh opened 2 years ago
Hi, thanks for your report.
I am not sure if this is desireable or not. My interpretation was, that a list of tuples refers to exact values, and the tuples itself do not contain lists or slices. Can you provide an example where this is necessary and can not be achieved with another method?
@phofl Thanks for your reply, I think your interpretation is reasonable, but there is usecase that we can use
out = df.loc[:, [(slice(None), "one"), ("qux", "two")]]
instead of writing all first levels manually
out = df.loc[:, [("baz", "one"), ("bar", "one"), ..., ("qux", "two")]]
Thx. Makes sense.
I think this is non trivial to do, especially without performance penalties
@phofl My intuition is that doing an extra check for slice(None) in tuple when indexing with list of labels. Do you mean the time cost for that will be expensive?
Currently, we pass the list of tuples into get_indexer that does not support slices. The list is not validated at all, hence I think this might be tricky.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
From Cross-section | MultiIndex / advanced indexing, it's ok to pass a
slice(None)
From Advanced indexing with hierarchical index | MultiIndex / advanced indexing, it's ok to pass a list of tuples
However, the error raise when using
slice(None)
in list likedf.loc[:, [(slice(None), "one")]]
Expected Behavior
The output show behave like
df.loc[:, (slice(None), "one")]
Installed Versions