6
6
7
7
from pandas ._config import get_option
8
8
9
- from pandas ._libs import algos as libalgos , lib
9
+ from pandas ._libs import algos as libalgos , hashtable as htable , lib
10
10
from pandas .compat .numpy import function as nv
11
11
from pandas .util ._decorators import (
12
12
Appender ,
50
50
from pandas .core import ops
51
51
from pandas .core .accessor import PandasDelegate , delegate_names
52
52
import 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
+ )
54
61
from pandas .core .base import NoNewAttributesMixin , PandasObject , _shared_docs
55
62
import pandas .core .common as com
56
63
from pandas .core .missing import interpolate_2d
@@ -1527,9 +1534,7 @@ def value_counts(self, dropna=True):
1527
1534
See Also
1528
1535
--------
1529
1536
Series.value_counts
1530
-
1531
1537
"""
1532
- from numpy import bincount
1533
1538
from pandas import Series , CategoricalIndex
1534
1539
1535
1540
code , cat = self ._codes , self .categories
@@ -1538,9 +1543,9 @@ def value_counts(self, dropna=True):
1538
1543
1539
1544
if dropna or clean :
1540
1545
obs = code if clean else code [mask ]
1541
- count = bincount (obs , minlength = ncat or 0 )
1546
+ count = np . bincount (obs , minlength = ncat or 0 )
1542
1547
else :
1543
- count = bincount (np .where (mask , code , ncat ))
1548
+ count = np . bincount (np .where (mask , code , ncat ))
1544
1549
ix = np .append (ix , - 1 )
1545
1550
1546
1551
ix = self ._constructor (ix , dtype = self .dtype , fastpath = True )
@@ -2329,9 +2334,6 @@ def mode(self, dropna=True):
2329
2334
-------
2330
2335
modes : `Categorical` (sorted)
2331
2336
"""
2332
-
2333
- import pandas ._libs .hashtable as htable
2334
-
2335
2337
codes = self ._codes
2336
2338
if dropna :
2337
2339
good = self ._codes != - 1
@@ -2671,8 +2673,6 @@ def _get_codes_for_values(values, categories):
2671
2673
"""
2672
2674
utility routine to turn values into codes given the specified categories
2673
2675
"""
2674
- from pandas .core .algorithms import _get_data_algo , _hashtables
2675
-
2676
2676
dtype_equal = is_dtype_equal (values .dtype , categories .dtype )
2677
2677
2678
2678
if dtype_equal :
@@ -2722,8 +2722,6 @@ def _recode_for_categories(codes, old_categories, new_categories):
2722
2722
>>> _recode_for_categories(codes, old_cat, new_cat)
2723
2723
array([ 1, 0, 0, -1])
2724
2724
"""
2725
- from pandas .core .algorithms import take_1d
2726
-
2727
2725
if len (old_categories ) == 0 :
2728
2726
# All null anyway, so just retain the nulls
2729
2727
return codes .copy ()
0 commit comments