-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add an option not to sort levels in MultiIndex.from_product? #14672
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
Any progress on this? |
@piotrjurkiewicz pandas is community supported; you are welcome to submit a patch |
There hasn't been any change here since 2016. I suggest closing this issue for the following reason: I believe this proposed change should not be done, as it would violate the main Mathematical logic of MultiIndex.from_product. It is a Cartesian product based on sets which are Ordered. Of course, I might be wrong, but here is one citation as an example: "A Cartesian Product is defined on an ordered set of Sets." https://www.sciencedirect.com/topics/computer-science/cartesian-product |
@ivasve but ordered != sorted. |
@kuraga Could you describe your thoughts in more detail, please? What part exactly are you referring to and why. Maybe I am missing something, I just need more info :-) Thanks. |
@ivasve , with |
Currently,
from_product
always sorts levels in the resulting MultiIndex. This means that the result does not necessarily have lexsorted labels/codes.PR #14062 adds an option to not sort levels when calling
from_product
. Compare:Using this option yields a few benefits:
The downside is that the result can be a little less intuitive, because levels and labels do not have the same sort order (#14015).
I'm suggesting this option because it was useful for xarray (to fix pydata/xarray#980) and might also be relevant for other advanced users.
The text was updated successfully, but these errors were encountered: