20
20
_maybe_convert_string_to_object ,
21
21
is_categorical , is_datetimelike_v_numeric ,
22
22
is_numeric_v_string_like , is_internal_type )
23
+ import pandas .core .algorithms as algos
23
24
from pandas .types .api import DatetimeTZDtype
24
25
25
26
from pandas .core .index import Index , MultiIndex , _ensure_index
@@ -286,8 +287,8 @@ def reindex_axis(self, indexer, method=None, axis=1, fill_value=None,
286
287
if fill_value is None :
287
288
fill_value = self .fill_value
288
289
289
- new_values = com .take_nd (self .values , indexer , axis ,
290
- fill_value = fill_value , mask_info = mask_info )
290
+ new_values = algos .take_nd (self .values , indexer , axis ,
291
+ fill_value = fill_value , mask_info = mask_info )
291
292
return self .make_block (new_values , fastpath = True )
292
293
293
294
def get (self , item ):
@@ -974,7 +975,7 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
974
975
975
976
"""
976
977
977
- # com .take_nd dispatches for DatetimeTZBlock, CategoricalBlock
978
+ # algos .take_nd dispatches for DatetimeTZBlock, CategoricalBlock
978
979
# so need to preserve types
979
980
# sparse is treated like an ndarray, but needs .get_values() shaping
980
981
@@ -984,12 +985,12 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
984
985
985
986
if fill_tuple is None :
986
987
fill_value = self .fill_value
987
- new_values = com .take_nd (values , indexer , axis = axis ,
988
- allow_fill = False )
988
+ new_values = algos .take_nd (values , indexer , axis = axis ,
989
+ allow_fill = False )
989
990
else :
990
991
fill_value = fill_tuple [0 ]
991
- new_values = com .take_nd (values , indexer , axis = axis ,
992
- allow_fill = True , fill_value = fill_value )
992
+ new_values = algos .take_nd (values , indexer , axis = axis ,
993
+ allow_fill = True , fill_value = fill_value )
993
994
994
995
if new_mgr_locs is None :
995
996
if axis == 0 :
@@ -1008,7 +1009,7 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
1008
1009
1009
1010
def diff (self , n , axis = 1 , mgr = None ):
1010
1011
""" return block for the diff of the values """
1011
- new_values = com .diff (self .values , n , axis = axis )
1012
+ new_values = algos .diff (self .values , n , axis = axis )
1012
1013
return [self .make_block (values = new_values , fastpath = True )]
1013
1014
1014
1015
def shift (self , periods , axis = 0 , mgr = None ):
@@ -2711,11 +2712,11 @@ def get_ftype_counts(self):
2711
2712
2712
2713
def get_dtypes (self ):
2713
2714
dtypes = np .array ([blk .dtype for blk in self .blocks ])
2714
- return com .take_1d (dtypes , self ._blknos , allow_fill = False )
2715
+ return algos .take_1d (dtypes , self ._blknos , allow_fill = False )
2715
2716
2716
2717
def get_ftypes (self ):
2717
2718
ftypes = np .array ([blk .ftype for blk in self .blocks ])
2718
- return com .take_1d (ftypes , self ._blknos , allow_fill = False )
2719
+ return algos .take_1d (ftypes , self ._blknos , allow_fill = False )
2719
2720
2720
2721
def __getstate__ (self ):
2721
2722
block_values = [b .values for b in self .blocks ]
@@ -3070,8 +3071,8 @@ def combine(self, blocks, copy=True):
3070
3071
new_blocks = []
3071
3072
for b in blocks :
3072
3073
b = b .copy (deep = copy )
3073
- b .mgr_locs = com .take_1d (inv_indexer , b .mgr_locs .as_array , axis = 0 ,
3074
- allow_fill = False )
3074
+ b .mgr_locs = algos .take_1d (inv_indexer , b .mgr_locs .as_array ,
3075
+ axis = 0 , allow_fill = False )
3075
3076
new_blocks .append (b )
3076
3077
3077
3078
new_axes = list (self .axes )
@@ -3451,8 +3452,8 @@ def value_getitem(placement):
3451
3452
new_blknos .fill (- 1 )
3452
3453
new_blknos [~ is_deleted ] = np .arange (self .nblocks -
3453
3454
len (removed_blknos ))
3454
- self ._blknos = com .take_1d (new_blknos , self ._blknos , axis = 0 ,
3455
- allow_fill = False )
3455
+ self ._blknos = algos .take_1d (new_blknos , self ._blknos , axis = 0 ,
3456
+ allow_fill = False )
3456
3457
self .blocks = tuple (blk for i , blk in enumerate (self .blocks )
3457
3458
if i not in set (removed_blknos ))
3458
3459
@@ -3632,10 +3633,10 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
3632
3633
blknos = self ._blknos [slobj ]
3633
3634
blklocs = self ._blklocs [slobj ]
3634
3635
else :
3635
- blknos = com .take_1d (self ._blknos , slobj , fill_value = - 1 ,
3636
- allow_fill = allow_fill )
3637
- blklocs = com .take_1d (self ._blklocs , slobj , fill_value = - 1 ,
3638
- allow_fill = allow_fill )
3636
+ blknos = algos .take_1d (self ._blknos , slobj , fill_value = - 1 ,
3637
+ allow_fill = allow_fill )
3638
+ blklocs = algos .take_1d (self ._blklocs , slobj , fill_value = - 1 ,
3639
+ allow_fill = allow_fill )
3639
3640
3640
3641
# When filling blknos, make sure blknos is updated before appending to
3641
3642
# blocks list, that way new blkno is exactly len(blocks).
@@ -3847,7 +3848,7 @@ def reindex(self, new_axis, indexer=None, method=None, fill_value=None,
3847
3848
else :
3848
3849
fill_value = np .nan
3849
3850
3850
- new_values = com .take_1d (values , indexer , fill_value = fill_value )
3851
+ new_values = algos .take_1d (values , indexer , fill_value = fill_value )
3851
3852
3852
3853
# fill if needed
3853
3854
if method is not None or limit is not None :
@@ -4676,8 +4677,8 @@ def get_mgr_concatenation_plan(mgr, indexers):
4676
4677
4677
4678
if 0 in indexers :
4678
4679
ax0_indexer = indexers .pop (0 )
4679
- blknos = com .take_1d (mgr ._blknos , ax0_indexer , fill_value = - 1 )
4680
- blklocs = com .take_1d (mgr ._blklocs , ax0_indexer , fill_value = - 1 )
4680
+ blknos = algos .take_1d (mgr ._blknos , ax0_indexer , fill_value = - 1 )
4681
+ blklocs = algos .take_1d (mgr ._blklocs , ax0_indexer , fill_value = - 1 )
4681
4682
else :
4682
4683
4683
4684
if mgr ._is_single_block :
@@ -4932,8 +4933,8 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):
4932
4933
4933
4934
else :
4934
4935
for ax , indexer in self .indexers .items ():
4935
- values = com .take_nd (values , indexer , axis = ax ,
4936
- fill_value = fill_value )
4936
+ values = algos .take_nd (values , indexer , axis = ax ,
4937
+ fill_value = fill_value )
4937
4938
4938
4939
return values
4939
4940
0 commit comments