-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Cannot subclass MultiIndex #11267
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
MultiIndex had several places where the output class was hard-coded to MultiIndex rather than cls, self.__class__, or the like. These have been replaced.
I just submitted pull request #11268 to fix this. |
can you provide a use-case for this (not objecting to the change though) |
Sure. I don't want to need to know the order of the indices in the MultiIndex. E.g. mi = MultiIndex((('a', 'b'), ('A', 'B')), ((0, 0), (0, 1), (1, 0), (1, 1)), names=('foo', 'bar'))
df = Series(..., index = mi) I want to be able to write something like df[mi(foo = 'a', bar = 'b')] or similar to get the correct Series elements. Maybe this functionality already exists in MultiIndex, but I didn't see it and decided to subclass. |
we've had discussions here
to allow:
xray calls this or maybe
if we allow the dict syntax you wouldn't normally want to have to do:
so, you don't need to sub-class at all, simply patch it in
kind of like that actually :) cc @shoyer |
Thanks for the answer! |
So this never got changed? Was there any special reason for not persuing this further? |
the PR went stale. in principle it is ok if you'd like to pick it up; needs more testing |
MultiIndex
cannot be subclassed because in several spots, including__new__
, the output class is hardcoded asMultiIndex
rather thancls
orself.__class__
or the like.This code illustrates the problem:
The last line should instead read
I have a patch in the works.
The text was updated successfully, but these errors were encountered: