Xarray: inconsistent behavior in stack/unstack along one dimension

Created on 28 May 2017  路  4Comments  路  Source: pydata/xarray

I am using Ubuntu 16, python 3.6, and xarray 0.9.1

A DataArray can be stacked along one dimension, but when unstack is called a ValueError is raised. It seems that either unstack should work, or calling stack should also raise a ValueError.

import xarray as xr

dims = ['a', 'b']
coords = {'a': range(2), 'b':range(2)}
values = [[0, 0], [0, 0]]

dar = xr.DataArray(values, coords, dims)

stacked = dar.stack(z=('a',))  # this works

unstack = stacked.unstack('z')  # this raises ValueError

bug

Most helpful comment

Hi @d-chambers

I am currently working for more consistent MultiIndex behaviour in #1426 .
I will take a look also for stack-unstack behavior.

All 4 comments

Hi @d-chambers

I am currently working for more consistent MultiIndex behaviour in #1426 .
I will take a look also for stack-unstack behavior.

Agreed, this does seem inconsistent. Thanks for the report!

This works with current master - so it can probably be closed? @d-chambers? (I think there is a error in the example - shouldn't it be unstack = stacked.unstack('z')?)

Yes, fixed the example. This seems to be fixed now, closing. Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mathause picture mathause  路  4Comments

Yefee picture Yefee  路  4Comments

ray306 picture ray306  路  4Comments

blaylockbk picture blaylockbk  路  4Comments

TomNicholas picture TomNicholas  路  4Comments