2
2
from __future__ import annotations
3
3
4
4
import collections
5
- from datetime import timedelta
5
+ import datetime as dt
6
6
import gc
7
7
import json
8
8
import operator
133
133
from pandas .core import (
134
134
algorithms as algos ,
135
135
arraylike ,
136
- common as com ,
137
136
indexing ,
138
137
missing ,
139
138
nanops ,
140
139
sample ,
141
140
)
141
+ from pandas .core import common # noqa: PDF018
142
142
from pandas .core .array_algos .replace import should_use_regex
143
143
from pandas .core .arrays import ExtensionArray
144
144
from pandas .core .base import PandasObject
@@ -1009,7 +1009,7 @@ def _rename(
1009
1009
continue
1010
1010
1011
1011
ax = self ._get_axis (axis_no )
1012
- f = com .get_rename_function (replacements )
1012
+ f = common .get_rename_function (replacements )
1013
1013
1014
1014
if level is not None :
1015
1015
level = ax ._get_level_number (level )
@@ -1240,7 +1240,7 @@ class name
1240
1240
if non_mapper :
1241
1241
newnames = v
1242
1242
else :
1243
- f = com .get_rename_function (v )
1243
+ f = common .get_rename_function (v )
1244
1244
curnames = self ._get_axis (axis ).names
1245
1245
newnames = [f (name ) for name in curnames ]
1246
1246
result ._set_axis_name (newnames , axis = axis , inplace = True )
@@ -1826,7 +1826,7 @@ def _drop_labels_or_levels(self, keys, axis: AxisInt = 0):
1826
1826
axis = self ._get_axis_number (axis )
1827
1827
1828
1828
# Validate keys
1829
- keys = com .maybe_make_list (keys )
1829
+ keys = common .maybe_make_list (keys )
1830
1830
invalid_keys = [
1831
1831
k for k in keys if not self ._is_label_or_level_reference (k , axis = axis )
1832
1832
]
@@ -4445,7 +4445,7 @@ def _drop_axis(
4445
4445
# Case for non-unique axis
4446
4446
else :
4447
4447
is_tuple_labels = is_nested_list_like (labels ) or isinstance (labels , tuple )
4448
- labels = ensure_object (com .index_labels_to_array (labels ))
4448
+ labels = ensure_object (common .index_labels_to_array (labels ))
4449
4449
if level is not None :
4450
4450
if not isinstance (axis , MultiIndex ):
4451
4451
raise AssertionError ("axis must be a MultiIndex" )
@@ -5236,7 +5236,7 @@ def _reindex_axes(
5236
5236
def _needs_reindex_multi (self , axes , method , level ) -> bool_t :
5237
5237
"""Check if we do need a multi reindex."""
5238
5238
return (
5239
- (com .count_not_none (* axes .values ()) == self ._AXIS_LEN )
5239
+ (common .count_not_none (* axes .values ()) == self ._AXIS_LEN )
5240
5240
and method is None
5241
5241
and level is None
5242
5242
and not self ._is_mixed_type
@@ -5359,7 +5359,7 @@ def filter(
5359
5359
one two three
5360
5360
rabbit 4 5 6
5361
5361
"""
5362
- nkw = com .count_not_none (items , like , regex )
5362
+ nkw = common .count_not_none (items , like , regex )
5363
5363
if nkw > 1 :
5364
5364
raise TypeError (
5365
5365
"Keyword arguments `items`, `like`, or `regex` "
@@ -5684,7 +5684,7 @@ def sample(
5684
5684
obj_len = self .shape [axis ]
5685
5685
5686
5686
# Process random_state argument
5687
- rs = com .random_state (random_state )
5687
+ rs = common .random_state (random_state )
5688
5688
5689
5689
size = sample .process_sampling_size (n , frac , replace )
5690
5690
if size is None :
@@ -5760,7 +5760,7 @@ def pipe(
5760
5760
... .pipe((func, 'arg2'), arg1=a, arg3=c)
5761
5761
... ) # doctest: +SKIP
5762
5762
"""
5763
- return com .pipe (self , func , * args , ** kwargs )
5763
+ return common .pipe (self , func , * args , ** kwargs )
5764
5764
5765
5765
# ----------------------------------------------------------------------
5766
5766
# Attribute access
@@ -9445,7 +9445,7 @@ def _where(
9445
9445
axis = self ._get_axis_number (axis )
9446
9446
9447
9447
# align the cond to same shape as myself
9448
- cond = com .apply_if_callable (cond , self )
9448
+ cond = common .apply_if_callable (cond , self )
9449
9449
if isinstance (cond , NDFrame ):
9450
9450
cond , _ = cond .align (self , join = "right" , broadcast_axis = 1 , copy = False )
9451
9451
else :
@@ -9467,9 +9467,9 @@ def _where(
9467
9467
if not is_bool_dtype (cond ):
9468
9468
raise ValueError (msg .format (dtype = cond .dtype ))
9469
9469
else :
9470
- for dt in cond .dtypes :
9471
- if not is_bool_dtype (dt ):
9472
- raise ValueError (msg .format (dtype = dt ))
9470
+ for _dt in cond .dtypes :
9471
+ if not is_bool_dtype (_dt ):
9472
+ raise ValueError (msg .format (dtype = _dt ))
9473
9473
else :
9474
9474
# GH#21947 we have an empty DataFrame/Series, could be object-dtype
9475
9475
cond = cond .astype (bool )
@@ -9747,7 +9747,7 @@ def where(
9747
9747
3 True True
9748
9748
4 True True
9749
9749
"""
9750
- other = com .apply_if_callable (other , self )
9750
+ other = common .apply_if_callable (other , self )
9751
9751
return self ._where (cond , other , inplace , axis , level )
9752
9752
9753
9753
@overload
@@ -9805,7 +9805,7 @@ def mask(
9805
9805
) -> NDFrameT | None :
9806
9806
9807
9807
inplace = validate_bool_kwarg (inplace , "inplace" )
9808
- cond = com .apply_if_callable (cond , self )
9808
+ cond = common .apply_if_callable (cond , self )
9809
9809
9810
9810
# see gh-21891
9811
9811
if not hasattr (cond , "__invert__" ):
@@ -10317,7 +10317,7 @@ def tz_localize(
10317
10317
"""
10318
10318
nonexistent_options = ("raise" , "NaT" , "shift_forward" , "shift_backward" )
10319
10319
if nonexistent not in nonexistent_options and not isinstance (
10320
- nonexistent , timedelta
10320
+ nonexistent , dt . timedelta
10321
10321
):
10322
10322
raise ValueError (
10323
10323
"The nonexistent argument must be one of 'raise', "
@@ -11470,7 +11470,7 @@ def min(
11470
11470
@doc (Rolling )
11471
11471
def rolling (
11472
11472
self ,
11473
- window : int | timedelta | str | BaseOffset | BaseIndexer ,
11473
+ window : int | dt . timedelta | str | BaseOffset | BaseIndexer ,
11474
11474
min_periods : int | None = None ,
11475
11475
center : bool_t = False ,
11476
11476
win_type : str | None = None ,
0 commit comments