@@ -1468,9 +1468,24 @@ def equals(self, other):
1468
1468
return False
1469
1469
return array_equivalent (self .values , other .values )
1470
1470
1471
- def _unstack (self , unstacker_t , new_columns ):
1472
- """Return a list of unstacked blocks of self"""
1473
- unstacker = unstacker_t (self .values .T )
1471
+ def _unstack (self , unstacker_func , new_columns ):
1472
+ """Return a list of unstacked blocks of self
1473
+
1474
+ Parameters
1475
+ ----------
1476
+ unstacker_func : callable
1477
+ Partially applied unstacker.
1478
+ new_columns : Index
1479
+ All columns of the unstacked BlockManager.
1480
+
1481
+ Returns
1482
+ -------
1483
+ blocks : list of Block
1484
+ New blocks of unstacked values.
1485
+ mask : array_like of bool
1486
+ The mask of columns of `blocks` we should keep.
1487
+ """
1488
+ unstacker = unstacker_func (self .values .T )
1474
1489
new_items = unstacker .get_new_columns ()
1475
1490
new_placement = new_columns .get_indexer (new_items )
1476
1491
new_values , mask = unstacker .get_new_values ()
@@ -1718,10 +1733,26 @@ def _slice(self, slicer):
1718
1733
def _try_cast_result (self , result , dtype = None ):
1719
1734
return result
1720
1735
1721
- def _unstack (self , unstacker_t , new_columns ):
1736
+ def _unstack (self , unstacker_func , new_columns ):
1737
+ """Return a list of unstacked blocks of self
1738
+
1739
+ Parameters
1740
+ ----------
1741
+ unstacker_func : callable
1742
+ Partially applied unstacker.
1743
+ new_columns : Index
1744
+ All columns of the unstacked BlockManager.
1745
+
1746
+ Returns
1747
+ -------
1748
+ blocks : list of Block
1749
+ New blocks of unstacked values.
1750
+ mask : array_like of bool
1751
+ The mask of columns of `blocks` we should keep.
1752
+ """
1722
1753
# NonConsolidatable blocks can have a single item only, so we return
1723
1754
# one block per item
1724
- unstacker = unstacker_t (self .values .T )
1755
+ unstacker = unstacker_func (self .values .T )
1725
1756
new_items = unstacker .get_new_columns ()
1726
1757
new_placement = new_columns .get_indexer (new_items )
1727
1758
new_values , mask = unstacker .get_new_values ()
@@ -4189,23 +4220,27 @@ def canonicalize(block):
4189
4220
return all (block .equals (oblock )
4190
4221
for block , oblock in zip (self_blocks , other_blocks ))
4191
4222
4192
- def unstack (self , unstacker_t ):
4223
+ def unstack (self , unstacker_func ):
4193
4224
"""Return a blockmanager with all blocks unstacked.
4194
4225
4195
4226
Parameters
4196
4227
----------
4197
- unstacker_t : type
4228
+ unstacker_func : callable
4198
4229
A (partially-applied) ``pd.core.reshape._Unstacker`` class.
4230
+
4231
+ Returns
4232
+ -------
4233
+ unstacked : BlockManager
4199
4234
"""
4200
- dummy = unstacker_t (np .empty ((0 , 0 )), value_columns = self .items )
4235
+ dummy = unstacker_func (np .empty ((0 , 0 )), value_columns = self .items )
4201
4236
new_columns = dummy .get_new_columns ()
4202
4237
new_index = dummy .get_new_index ()
4203
4238
new_blocks = []
4204
4239
columns_mask = []
4205
4240
4206
4241
for blk in self .blocks :
4207
4242
blocks , mask = blk ._unstack (
4208
- partial (unstacker_t ,
4243
+ partial (unstacker_func ,
4209
4244
value_columns = self .items [blk .mgr_locs .indexer ]),
4210
4245
new_columns )
4211
4246
0 commit comments