-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
MultiIndex.from_product could accept MultiIndex #36509
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
can u show an example |
One of the symptoms of this issue is #34019, which could be fixed with #38558, however, that leads to
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
----> 1 xr.DataArray(np.ones([3, 3, 3]), dims=["x", "y", "z"], name="foo").stack(a=("x", "y")).to_dataframe()
/nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/xarray/core/dataarray.py in to_dataframe(self, name, dim_order) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/xarray/core/dataset.py in _to_dataframe(self, ordered_dims) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/xarray/core/coordinates.py in to_index(self, ordered_dims) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in from_product(cls, iterables, sortorder, names) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in new(cls, levels, codes, sortorder, names, dtype, copy, name, verify_integrity, _set_identity) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in _verify_integrity(self, codes, levels) pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.get() /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in levels(self) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in (.0) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in _shallow_copy(self, values, name, levels, codes, dtype, sortorder, names, _set_identity) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in new(cls, levels, codes, sortorder, names, dtype, copy, name, verify_integrity, _set_identity) /nix/store/db2v0kg0x1gsxc34g5qn6s8hzy1v9wrz-python3-3.8.6-env/lib/python3.8/site-packages/pandas/core/indexes/multi.py in _set_names(self, names, level, validate) ValueError: Names should be list-like for a MultiIndex |
Thanks for the issue, but it appears this hasn't gotten traction in a while so closing |
Is your feature request related to a problem?
The problem is in xarray.DataArray.to_dataframe() which uses MultiIndex.from_product() to build the index based on the array coordinates.
When an xarray has a MultiIndex as one of the coordinates, from_product is called with a Multiindex as one of the iterable. This raises an exception, as discussed here pydata/xarray#3008
Describe the solution you'd like
I've implemented a solution in xarray [PR ##4442], this close the issue for xarray.
However, the solution could be ported to from_product to allow this method to accept MultiIndex. I'm not sure it is of great interest for the users, but at least the solution exists and is relatively simple.
API breaking implications
none breaking
Describe alternatives you've considered
none
The text was updated successfully, but these errors were encountered: