55
55
from pandas .formats .printing import pprint_thing
56
56
from pandas .util .validators import validate_kwargs
57
57
58
- import pandas .core .algorithms as algos
58
+ import pandas .core .algorithms as algorithms
59
59
import pandas .core .common as com
60
60
from pandas .core .config import option_context
61
61
62
- from pandas .libs import lib , tslib , algos as _algos
62
+ from pandas .libs import lib , libalgos , NaT , iNaT
63
63
from pandas .libs .lib import Timestamp , count_level_2d
64
64
65
65
_doc_template = """
@@ -1473,11 +1473,11 @@ def shift(self, periods=1, freq=None, axis=0):
1473
1473
1474
1474
# filled in by Cython
1475
1475
indexer = np .zeros_like (labels )
1476
- _algos .group_shift_indexer (indexer , labels , ngroups , periods )
1476
+ libalgos .group_shift_indexer (indexer , labels , ngroups , periods )
1477
1477
1478
1478
output = {}
1479
1479
for name , obj in self ._iterate_slices ():
1480
- output [name ] = algos .take_nd (obj .values , indexer )
1480
+ output [name ] = algorithms .take_nd (obj .values , indexer )
1481
1481
1482
1482
return self ._wrap_transformed_output (output )
1483
1483
@@ -1814,13 +1814,13 @@ def _get_cython_function(self, kind, how, values, is_numeric):
1814
1814
def get_func (fname ):
1815
1815
# see if there is a fused-type version of function
1816
1816
# only valid for numeric
1817
- f = getattr (_algos , fname , None )
1817
+ f = getattr (libalgos , fname , None )
1818
1818
if f is not None and is_numeric :
1819
1819
return f
1820
1820
1821
1821
# otherwise find dtype-specific version, falling back to object
1822
1822
for dt in [dtype_str , 'object' ]:
1823
- f = getattr (_algos , "%s_%s" % (fname , dtype_str ), None )
1823
+ f = getattr (libalgos , "%s_%s" % (fname , dtype_str ), None )
1824
1824
if f is not None :
1825
1825
return f
1826
1826
@@ -1900,7 +1900,7 @@ def _cython_operation(self, kind, values, how, axis):
1900
1900
elif is_integer_dtype (values ):
1901
1901
# we use iNaT for the missing value on ints
1902
1902
# so pre-convert to guard this condition
1903
- if (values == tslib . iNaT ).any ():
1903
+ if (values == iNaT ).any ():
1904
1904
values = _ensure_float64 (values )
1905
1905
else :
1906
1906
values = values .astype ('int64' , copy = False )
@@ -1942,7 +1942,7 @@ def _cython_operation(self, kind, values, how, axis):
1942
1942
result , values , labels , func , is_numeric , is_datetimelike )
1943
1943
1944
1944
if is_integer_dtype (result ):
1945
- mask = result == tslib . iNaT
1945
+ mask = result == iNaT
1946
1946
if mask .any ():
1947
1947
result = result .astype ('float64' )
1948
1948
result [mask ] = np .nan
@@ -2033,7 +2033,8 @@ def _aggregate_series_fast(self, obj, func):
2033
2033
dummy = obj ._get_values (slice (None , 0 )).to_dense ()
2034
2034
indexer = get_group_index_sorter (group_index , ngroups )
2035
2035
obj = obj .take (indexer , convert = False )
2036
- group_index = algos .take_nd (group_index , indexer , allow_fill = False )
2036
+ group_index = algorithms .take_nd (
2037
+ group_index , indexer , allow_fill = False )
2037
2038
grouper = lib .SeriesGrouper (obj , func , group_index , ngroups ,
2038
2039
dummy )
2039
2040
result , counts = grouper .get_result ()
@@ -2131,7 +2132,7 @@ def groups(self):
2131
2132
# GH 3881
2132
2133
result = {}
2133
2134
for key , value in zip (self .binlabels , self .bins ):
2134
- if key is not tslib . NaT :
2135
+ if key is not NaT :
2135
2136
result [key ] = value
2136
2137
return result
2137
2138
@@ -2158,7 +2159,7 @@ def get_iterator(self, data, axis=0):
2158
2159
2159
2160
start = 0
2160
2161
for edge , label in zip (self .bins , self .binlabels ):
2161
- if label is not tslib . NaT :
2162
+ if label is not NaT :
2162
2163
yield label , slicer (start , edge )
2163
2164
start = edge
2164
2165
@@ -2172,7 +2173,7 @@ def indices(self):
2172
2173
i = 0
2173
2174
for label , bin in zip (self .binlabels , self .bins ):
2174
2175
if i < bin :
2175
- if label is not tslib . NaT :
2176
+ if label is not NaT :
2176
2177
indices [label ] = list (range (i , bin ))
2177
2178
i = bin
2178
2179
return indices
@@ -2382,7 +2383,8 @@ def group_index(self):
2382
2383
2383
2384
def _make_labels (self ):
2384
2385
if self ._labels is None or self ._group_index is None :
2385
- labels , uniques = algos .factorize (self .grouper , sort = self .sort )
2386
+ labels , uniques = algorithms .factorize (
2387
+ self .grouper , sort = self .sort )
2386
2388
uniques = Index (uniques , name = self .name )
2387
2389
self ._labels = labels
2388
2390
self ._group_index = uniques
@@ -2927,7 +2929,7 @@ def _transform_fast(self, func):
2927
2929
2928
2930
ids , _ , ngroup = self .grouper .group_info
2929
2931
cast = (self .size ().fillna (0 ) > 0 ).any ()
2930
- out = algos .take_1d (func ().values , ids )
2932
+ out = algorithms .take_1d (func ().values , ids )
2931
2933
if cast :
2932
2934
out = self ._try_cast (out , self .obj )
2933
2935
return Series (out , index = self .obj .index , name = self .obj .name )
@@ -2984,7 +2986,7 @@ def nunique(self, dropna=True):
2984
2986
except TypeError : # catches object dtypes
2985
2987
assert val .dtype == object , \
2986
2988
'val.dtype must be object, got %s' % val .dtype
2987
- val , _ = algos .factorize (val , sort = False )
2989
+ val , _ = algorithms .factorize (val , sort = False )
2988
2990
sorter = np .lexsort ((val , ids ))
2989
2991
_isnull = lambda a : a == - 1
2990
2992
else :
@@ -3068,7 +3070,7 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
3068
3070
ids , val = ids [mask ], val [mask ]
3069
3071
3070
3072
if bins is None :
3071
- lab , lev = algos .factorize (val , sort = True )
3073
+ lab , lev = algorithms .factorize (val , sort = True )
3072
3074
else :
3073
3075
cat , bins = cut (val , bins , retbins = True )
3074
3076
# bins[:-1] for backward compat;
@@ -3107,7 +3109,7 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
3107
3109
if dropna :
3108
3110
m = ids [lab == - 1 ]
3109
3111
if _np_version_under1p8 :
3110
- mi , ml = algos .factorize (m )
3112
+ mi , ml = algorithms .factorize (m )
3111
3113
d [ml ] = d [ml ] - np .bincount (mi )
3112
3114
else :
3113
3115
np .add .at (d , m , - 1 )
@@ -3129,7 +3131,7 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
3129
3131
out = _ensure_int64 (out )
3130
3132
return Series (out , index = mi , name = self .name )
3131
3133
3132
- # for compat. with algos .value_counts need to ensure every
3134
+ # for compat. with libalgos .value_counts need to ensure every
3133
3135
# bin is present at every index level, null filled with zeros
3134
3136
diff = np .zeros (len (out ), dtype = 'bool' )
3135
3137
for lab in labels [:- 1 ]:
@@ -3700,7 +3702,7 @@ def _transform_fast(self, result, obj):
3700
3702
ids , _ , ngroup = self .grouper .group_info
3701
3703
output = []
3702
3704
for i , _ in enumerate (result .columns ):
3703
- res = algos .take_1d (result .iloc [:, i ].values , ids )
3705
+ res = algorithms .take_1d (result .iloc [:, i ].values , ids )
3704
3706
if cast :
3705
3707
res = self ._try_cast (res , obj .iloc [:, i ])
3706
3708
output .append (res )
@@ -4188,7 +4190,7 @@ def __init__(self, data, labels, ngroups, axis=0):
4188
4190
@cache_readonly
4189
4191
def slabels (self ):
4190
4192
# Sorted labels
4191
- return algos .take_nd (self .labels , self .sort_idx , allow_fill = False )
4193
+ return algorithms .take_nd (self .labels , self .sort_idx , allow_fill = False )
4192
4194
4193
4195
@cache_readonly
4194
4196
def sort_idx (self ):
0 commit comments