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
If I call .stack() on a DataArray, and any of the dimensions to be stacked already has a MultiIndex on it, I get an error:
TypeError: Must pass list-like as `names`.
Maybe it doesn't make sense for .stack() to work on an existing MultiIndex, but that should probably be documented, and perhaps throw a more informative error.
Here's the full trace:
Traceback (most recent call last)
<ipython-input-6-ce81ac38d71e> in <module>()
----> 1 xr_one_flat_stacked = xr_one_flat.stack(alphanumeric=("letters", "numbers"))
2 xr_one_flat_stacked
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/xarray/core/dataarray.pyc in stack(self, **dimensions)
1027 DataArray.unstack
1028 """
-> 1029 ds = self._to_temp_dataset().stack(**dimensions)
1030 return self._from_temp_dataset(ds)
1031
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/xarray/core/dataset.pyc in stack(self, **dimensions)
1832 result = self
1833 for new_dim, dims in dimensions.items():
-> 1834 result = result._stack_once(dims, new_dim)
1835 return result
1836
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/xarray/core/dataset.pyc in _stack_once(self, dims, new_dim)
1801 else level
1802 for level in levels]
-> 1803 idx = utils.multiindex_from_product_levels(levels, names=dims)
1804 variables[new_dim] = IndexVariable(new_dim, idx)
1805
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/xarray/core/utils.pyc in multiindex_from_product_levels(levels, names)
79 indexing='ij')
80 labels = [x.ravel() for x in labels_mesh]
---> 81 return pd.MultiIndex(levels, labels, sortorder=0, names=names)
82
83
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/pandas/indexes/multi.pyc in __new__(cls, levels, labels, sortorder, names, copy, verify_integrity, _set_identity, name, **kwargs)
103 if names is not None:
104 # handles name validation
--> 105 result._set_names(names)
106
107 if sortorder is not None:
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/pandas/indexes/multi.pyc in _set_names(self, names, level, validate)
505 # set the name
506 for l, name in zip(level, names):
--> 507 self.levels[l].rename(name, inplace=True)
508
509 names = property(fset=_set_names, fget=_get_names,
/Users/jjpr/anaconda/envs/dldata/lib/python2.7/site-packages/pandas/indexes/base.pyc in set_names(self, names, level, inplace)
997
998 if not is_list_like(names) and level is None and self.nlevels > 1:
--> 999 raise TypeError("Must pass list-like as `names`.")
1000
1001 if not is_list_like(names):
TypeError: Must pass list-like as `names`.
The text was updated successfully, but these errors were encountered:
I agree that a better error message would be helpful here, but I do think that stack can still be meaningfully if one of the components is a MultiIndex (e.g., by combining the existing levels with the new levels to be stacked)
I have been playing around with the MultiIndexes as part of #1317, so I could take a stab at implementing some sort of stack which combines the levels etc.
If I call .stack() on a DataArray, and any of the dimensions to be stacked already has a MultiIndex on it, I get an error:
TypeError: Must pass list-like as `names`.
Maybe it doesn't make sense for .stack() to work on an existing MultiIndex, but that should probably be documented, and perhaps throw a more informative error.
Here's the full trace:
The text was updated successfully, but these errors were encountered: