Skip to content

DataArray.to_series() creates a MultiIndex even for 1D data #1548

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

Closed
shoyer opened this issue Sep 2, 2017 · 0 comments
Closed

DataArray.to_series() creates a MultiIndex even for 1D data #1548

shoyer opened this issue Sep 2, 2017 · 0 comments

Comments

@shoyer
Copy link
Member

shoyer commented Sep 2, 2017

xref #1542

This appears when using the development version of pandas:

In [7]: import pandas as pd

In [8]: pd.Series(range(5))
Out[8]:
0    0
1    1
2    2
3    3
4    4
dtype: int64

In [9]: pd.Series(range(5)).to_xarray().to_series()
Out[9]:
index
0        0
1        1
2        2
3        3
4        4
dtype: int64

In [10]: pd.Series(range(5)).to_xarray().to_series().index
Out[10]:
MultiIndex(levels=[[0, 1, 2, 3, 4]],
           labels=[[0, 1, 2, 3, 4]],
           names=['index'])

I think the problem boils down to these lines:

def to_index(self, ordered_dims=None):
"""Convert all index coordinates into a :py:class:`pandas.MultiIndex`
"""
if ordered_dims is None:
ordered_dims = self.dims
indexes = [self._data.get_index(k) for k in ordered_dims]
return pd.MultiIndex.from_product(indexes, names=list(ordered_dims))

We really want a normal Index for the coordinates from 1D data, not a MultiIndex. MultiIndex.from_product used to return different types depending on how it was called, but in pandas-dev/pandas#17236 it was fixed to always return a MultiIndex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant