You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dimensions of the generated xarray.Dataset is sorted in ascending order for lag.
This is true for any entry (like the commented out np.random.randn(4) line)
The problem is that for unstacking (in pandas or with to_xarray()), we simply use the order of MultiIndex.labels, instead of order of appearance on the MultiIndex. See pydata/xarray#906 for an extensive discussion of the issue in the context of xarray's unstack() method.
One possible fix would be to change unstack() in both pandas and xarray to no longer use MultiIndex labels directly but instead always pull out in order of appearance, i.e.,
In [14]: solution.index.levels[0].take(pd.unique(solution.index.labels[0]))
Out[14]: Int64Index([3, 2, 1, 0], dtype='int64', name='lag')
This would be an API change but possibly would be a welcome development. The order of levels is mostly an implementation detail that users would rather not need to think about. I suppose there could also potentially be a keyword argument to switch this behavior on/off in unstack() (and possibly to_xarray()).
Alternatively, #14672 proposes a new keyword argument to MultiIndex.from_product to avoid sorting levels when constructing the MultiIndex.
Code Sample, a copy-pastable example if possible
Output:
Problem description
The dimensions of the generated
xarray.Dataset
is sorted in ascending order forlag
.This is true for any entry (like the commented out
np.random.randn(4)
line)Expected Output
Output of
pd.show_versions()
pandas: 0.19.1
nose: None
pip: 9.0.1
setuptools: 30.2.0
Cython: None
numpy: 1.11.2
scipy: 0.18.1
statsmodels: None
xarray: 0.8.2
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: