File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -1573,14 +1573,13 @@ def _unstack_once(
1573
1573
"""
1574
1574
1575
1575
reordered = self .transpose (..., dim )
1576
- shape = reordered .shape
1577
1576
new_dim_sizes = [lev .size for lev in index .levels ]
1578
1577
new_dim_names = index .names
1579
1578
indexer = index .codes
1580
1579
1581
1580
# Potentially we could replace `len(other_dims)` with just `-1`
1582
1581
other_dims = [d for d in self .dims if d != dim ]
1583
- new_shape = tuple (list (shape [: len (other_dims )]) + new_dim_sizes )
1582
+ new_shape = tuple (list (reordered . shape [: len (other_dims )]) + new_dim_sizes )
1584
1583
new_dims = reordered .dims [: len (other_dims )] + new_dim_names
1585
1584
1586
1585
if fill_value is dtypes .NA :
@@ -1594,14 +1593,17 @@ def _unstack_once(
1594
1593
dtype = self .dtype
1595
1594
1596
1595
if sparse :
1596
+ # unstacking a dense multitindexed array to a sparse array
1597
+ # Use the sparse.COO constructor until sparse supports advanced indexing
1598
+ # https://github.com/pydata/sparse/issues/114
1597
1599
# TODO: how do we allow different sparse array types
1598
1600
from sparse import COO
1599
1601
1600
1602
codes = zip (* index .codes )
1601
- if not shape [: - 1 ] :
1603
+ if reordered . ndim == 1 :
1602
1604
indexes = codes
1603
1605
else :
1604
- sizes = itertools .product (range (* shape [:- 1 ]))
1606
+ sizes = itertools .product (range (* reordered . shape [:- 1 ]))
1605
1607
tuple_indexes = itertools .product (sizes , codes )
1606
1608
indexes = map (lambda x : list (itertools .chain (* x )), tuple_indexes ) # type: ignore
1607
1609
You can’t perform that action at this time.
0 commit comments