66
77from pandas ._config import get_option
88
9- from pandas ._libs import algos as libalgos , lib
9+ from pandas ._libs import algos as libalgos , hashtable as htable , lib
1010from pandas .compat .numpy import function as nv
1111from pandas .util ._decorators import (
1212 Appender ,
5050from pandas .core import ops
5151from pandas .core .accessor import PandasDelegate , delegate_names
5252import pandas .core .algorithms as algorithms
53- from pandas .core .algorithms import factorize , take , take_1d , unique1d
53+ from pandas .core .algorithms import (
54+ _get_data_algo ,
55+ _hashtables ,
56+ factorize ,
57+ take ,
58+ take_1d ,
59+ unique1d ,
60+ )
5461from pandas .core .base import NoNewAttributesMixin , PandasObject , _shared_docs
5562import pandas .core .common as com
5663from pandas .core .missing import interpolate_2d
@@ -1527,9 +1534,7 @@ def value_counts(self, dropna=True):
15271534 See Also
15281535 --------
15291536 Series.value_counts
1530-
15311537 """
1532- from numpy import bincount
15331538 from pandas import Series , CategoricalIndex
15341539
15351540 code , cat = self ._codes , self .categories
@@ -1538,9 +1543,9 @@ def value_counts(self, dropna=True):
15381543
15391544 if dropna or clean :
15401545 obs = code if clean else code [mask ]
1541- count = bincount (obs , minlength = ncat or 0 )
1546+ count = np . bincount (obs , minlength = ncat or 0 )
15421547 else :
1543- count = bincount (np .where (mask , code , ncat ))
1548+ count = np . bincount (np .where (mask , code , ncat ))
15441549 ix = np .append (ix , - 1 )
15451550
15461551 ix = self ._constructor (ix , dtype = self .dtype , fastpath = True )
@@ -2329,9 +2334,6 @@ def mode(self, dropna=True):
23292334 -------
23302335 modes : `Categorical` (sorted)
23312336 """
2332-
2333- import pandas ._libs .hashtable as htable
2334-
23352337 codes = self ._codes
23362338 if dropna :
23372339 good = self ._codes != - 1
@@ -2671,8 +2673,6 @@ def _get_codes_for_values(values, categories):
26712673 """
26722674 utility routine to turn values into codes given the specified categories
26732675 """
2674- from pandas .core .algorithms import _get_data_algo , _hashtables
2675-
26762676 dtype_equal = is_dtype_equal (values .dtype , categories .dtype )
26772677
26782678 if dtype_equal :
@@ -2722,8 +2722,6 @@ def _recode_for_categories(codes, old_categories, new_categories):
27222722 >>> _recode_for_categories(codes, old_cat, new_cat)
27232723 array([ 1, 0, 0, -1])
27242724 """
2725- from pandas .core .algorithms import take_1d
2726-
27272725 if len (old_categories ) == 0 :
27282726 # All null anyway, so just retain the nulls
27292727 return codes .copy ()
0 commit comments