File tree 2 files changed +6
-5
lines changed
2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,8 @@ def maybe_to_categorical(array):
127
127
""" coerce to a categorical if a series is given """
128
128
if isinstance (array , (ABCSeries , ABCCategoricalIndex )):
129
129
return array ._values
130
+ elif isinstance (array , np .ndarray ):
131
+ return Categorical (array )
130
132
return array
131
133
132
134
Original file line number Diff line number Diff line change @@ -4082,20 +4082,19 @@ def unstack(self, unstacker):
4082
4082
new_columns = dummy .get_new_columns ()
4083
4083
new_index = dummy .get_new_index ()
4084
4084
new_blocks = []
4085
- mask_blocks = np .zeros_like (new_columns , dtype = bool )
4085
+ mask_columns = np .zeros_like (new_columns , dtype = bool )
4086
4086
4087
4087
for blk in self .blocks :
4088
4088
bunstacker = unstacker (
4089
4089
blk .values .T , value_columns = self .items [blk .mgr_locs .indexer ])
4090
4090
new_items = bunstacker .get_new_columns ()
4091
4091
new_values , mask = bunstacker .get_new_values ()
4092
4092
new_placement = new_columns .get_indexer (new_items )
4093
- mask_blocks [new_placement ] = mask .any (0 )
4093
+ mask_columns [new_placement ] = mask .any (0 )
4094
4094
new_blocks .extend (blk ._unstack (new_values .T , new_placement ))
4095
4095
4096
- new_blocks = [b for b , keep in zip (new_blocks , mask_blocks ) if keep ]
4097
- new_axes = [new_columns [mask_blocks ], new_index ]
4098
- bm = BlockManager (new_blocks , new_axes )
4096
+ bm = BlockManager (new_blocks , [new_columns , new_index ])
4097
+ bm = bm .take (mask_columns .nonzero ()[0 ], axis = 0 )
4099
4098
return bm
4100
4099
4101
4100
You can’t perform that action at this time.
0 commit comments