@@ -1484,9 +1484,24 @@ def equals(self, other):
1484
1484
return False
1485
1485
return array_equivalent (self .values , other .values )
1486
1486
1487
- def _unstack (self , unstacker_t , new_columns ):
1488
- """Return a list of unstacked blocks of self"""
1489
- unstacker = unstacker_t (self .values .T )
1487
+ def _unstack (self , unstacker_func , new_columns ):
1488
+ """Return a list of unstacked blocks of self
1489
+
1490
+ Parameters
1491
+ ----------
1492
+ unstacker_func : callable
1493
+ Partially applied unstacker.
1494
+ new_columns : Index
1495
+ All columns of the unstacked BlockManager.
1496
+
1497
+ Returns
1498
+ -------
1499
+ blocks : list of Block
1500
+ New blocks of unstacked values.
1501
+ mask : array_like of bool
1502
+ The mask of columns of `blocks` we should keep.
1503
+ """
1504
+ unstacker = unstacker_func (self .values .T )
1490
1505
new_items = unstacker .get_new_columns ()
1491
1506
new_placement = new_columns .get_indexer (new_items )
1492
1507
new_values , mask = unstacker .get_new_values ()
@@ -1726,10 +1741,26 @@ def _slice(self, slicer):
1726
1741
def _try_cast_result (self , result , dtype = None ):
1727
1742
return result
1728
1743
1729
- def _unstack (self , unstacker_t , new_columns ):
1744
+ def _unstack (self , unstacker_func , new_columns ):
1745
+ """Return a list of unstacked blocks of self
1746
+
1747
+ Parameters
1748
+ ----------
1749
+ unstacker_func : callable
1750
+ Partially applied unstacker.
1751
+ new_columns : Index
1752
+ All columns of the unstacked BlockManager.
1753
+
1754
+ Returns
1755
+ -------
1756
+ blocks : list of Block
1757
+ New blocks of unstacked values.
1758
+ mask : array_like of bool
1759
+ The mask of columns of `blocks` we should keep.
1760
+ """
1730
1761
# NonConsolidatable blocks can have a single item only, so we return
1731
1762
# one block per item
1732
- unstacker = unstacker_t (self .values .T )
1763
+ unstacker = unstacker_func (self .values .T )
1733
1764
new_items = unstacker .get_new_columns ()
1734
1765
new_placement = new_columns .get_indexer (new_items )
1735
1766
new_values , mask = unstacker .get_new_values ()
@@ -4197,23 +4228,27 @@ def canonicalize(block):
4197
4228
return all (block .equals (oblock )
4198
4229
for block , oblock in zip (self_blocks , other_blocks ))
4199
4230
4200
- def unstack (self , unstacker_t ):
4231
+ def unstack (self , unstacker_func ):
4201
4232
"""Return a blockmanager with all blocks unstacked.
4202
4233
4203
4234
Parameters
4204
4235
----------
4205
- unstacker_t : type
4236
+ unstacker_func : callable
4206
4237
A (partially-applied) ``pd.core.reshape._Unstacker`` class.
4238
+
4239
+ Returns
4240
+ -------
4241
+ unstacked : BlockManager
4207
4242
"""
4208
- dummy = unstacker_t (np .empty ((0 , 0 )), value_columns = self .items )
4243
+ dummy = unstacker_func (np .empty ((0 , 0 )), value_columns = self .items )
4209
4244
new_columns = dummy .get_new_columns ()
4210
4245
new_index = dummy .get_new_index ()
4211
4246
new_blocks = []
4212
4247
columns_mask = []
4213
4248
4214
4249
for blk in self .blocks :
4215
4250
blocks , mask = blk ._unstack (
4216
- partial (unstacker_t ,
4251
+ partial (unstacker_func ,
4217
4252
value_columns = self .items [blk .mgr_locs .indexer ]),
4218
4253
new_columns )
4219
4254
0 commit comments