Skip to content

Commit c243b44

Browse files
alphacrackbishwas jha
authored andcommitted
STYLE enable pylint's redefined-outer-name (pandas-dev#49671)
* fix warning for pandas/core/dtypes/cast.py, pandas/core/dtypes/dtypes.py, pandas/core/indexes/base.py * fix warning for pandas/core/dtypes/cast.py, pandas/core/dtypes/dtypes.py, pandas/core/indexes/base.py * fix warning for pandas/core/dtypes/cast.py, pandas/core/dtypes/dtypes.py, pandas/core/indexes/base.py * fix warning for pandas/core/dtypes/cast.py, pandas/core/dtypes/dtypes.py, pandas/core/indexes/base.py Co-authored-by: bishwas jha <[email protected]>
1 parent 568e46a commit c243b44

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

pandas/core/dtypes/cast.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
from __future__ import annotations
66

7-
from datetime import (
8-
datetime,
9-
timedelta,
10-
)
7+
import datetime as dt
118
import functools
129
from typing import (
1310
TYPE_CHECKING,
@@ -73,7 +70,7 @@
7370
is_string_dtype,
7471
is_timedelta64_dtype,
7572
is_unsigned_integer_dtype,
76-
pandas_dtype,
73+
pandas_dtype as pandas_dtype_func,
7774
)
7875
from pandas.core.dtypes.dtypes import (
7976
CategoricalDtype,
@@ -170,9 +167,9 @@ def maybe_box_datetimelike(value: Scalar, dtype: Dtype | None = None) -> Scalar:
170167
"""
171168
if dtype == _dtype_obj:
172169
pass
173-
elif isinstance(value, (np.datetime64, datetime)):
170+
elif isinstance(value, (np.datetime64, dt.datetime)):
174171
value = Timestamp(value)
175-
elif isinstance(value, (np.timedelta64, timedelta)):
172+
elif isinstance(value, (np.timedelta64, dt.timedelta)):
176173
value = Timedelta(value)
177174

178175
return value
@@ -761,7 +758,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
761758

762759
dtype = _dtype_obj
763760

764-
elif isinstance(val, (np.datetime64, datetime)):
761+
elif isinstance(val, (np.datetime64, dt.datetime)):
765762
try:
766763
val = Timestamp(val)
767764
except OutOfBoundsDatetime:
@@ -781,7 +778,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
781778
# return datetimetz as object
782779
return _dtype_obj, val
783780

784-
elif isinstance(val, (np.timedelta64, timedelta)):
781+
elif isinstance(val, (np.timedelta64, dt.timedelta)):
785782
try:
786783
val = Timedelta(val)
787784
except (OutOfBoundsTimedelta, OverflowError):
@@ -1096,10 +1093,10 @@ def convert_dtypes(
10961093
if not convert_string or inferred_dtype == "bytes":
10971094
return input_array.dtype
10981095
else:
1099-
return pandas_dtype("string")
1096+
return pandas_dtype_func("string")
11001097

11011098
if convert_integer:
1102-
target_int_dtype = pandas_dtype("Int64")
1099+
target_int_dtype = pandas_dtype_func("Int64")
11031100

11041101
if is_integer_dtype(input_array.dtype):
11051102
from pandas.core.arrays.integer import INT_STR_TO_DTYPE
@@ -1128,15 +1125,15 @@ def convert_dtypes(
11281125
from pandas.core.arrays.floating import FLOAT_STR_TO_DTYPE
11291126

11301127
inferred_float_dtype: DtypeObj = FLOAT_STR_TO_DTYPE.get(
1131-
input_array.dtype.name, pandas_dtype("Float64")
1128+
input_array.dtype.name, pandas_dtype_func("Float64")
11321129
)
11331130
# if we could also convert to integer, check if all floats
11341131
# are actually integers
11351132
if convert_integer:
11361133
# TODO: de-dup with maybe_cast_to_integer_array?
11371134
arr = input_array[notna(input_array)]
11381135
if (arr.astype(int) == arr).all():
1139-
inferred_dtype = pandas_dtype("Int64")
1136+
inferred_dtype = pandas_dtype_func("Int64")
11401137
else:
11411138
inferred_dtype = inferred_float_dtype
11421139
else:
@@ -1146,13 +1143,13 @@ def convert_dtypes(
11461143
and is_object_dtype(input_array.dtype)
11471144
and inferred_dtype == "mixed-integer-float"
11481145
):
1149-
inferred_dtype = pandas_dtype("Float64")
1146+
inferred_dtype = pandas_dtype_func("Float64")
11501147

11511148
if convert_boolean:
11521149
if is_bool_dtype(input_array.dtype):
1153-
inferred_dtype = pandas_dtype("boolean")
1150+
inferred_dtype = pandas_dtype_func("boolean")
11541151
elif isinstance(inferred_dtype, str) and inferred_dtype == "boolean":
1155-
inferred_dtype = pandas_dtype("boolean")
1152+
inferred_dtype = pandas_dtype_func("boolean")
11561153

11571154
if isinstance(inferred_dtype, str):
11581155
# If we couldn't do anything else, then we retain the dtype
@@ -1578,7 +1575,7 @@ def construct_1d_arraylike_from_scalar(
15781575
def _maybe_box_and_unbox_datetimelike(value: Scalar, dtype: DtypeObj):
15791576
# Caller is responsible for checking dtype.kind in ["m", "M"]
15801577

1581-
if isinstance(value, datetime):
1578+
if isinstance(value, dt.datetime):
15821579
# we dont want to box dt64, in particular datetime64("NaT")
15831580
value = maybe_box_datetimelike(value, dtype)
15841581

pandas/core/dtypes/dtypes.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
NaTType,
2424
Period,
2525
Timestamp,
26-
dtypes,
2726
timezones,
2827
to_offset,
2928
tz_compare,
3029
)
30+
from pandas._libs.tslibs.dtypes import (
31+
NpyDatetimeUnit,
32+
PeriodDtypeBase,
33+
)
3134
from pandas._typing import (
3235
Dtype,
3336
DtypeObj,
@@ -716,10 +719,10 @@ def _creso(self) -> int:
716719
The NPY_DATETIMEUNIT corresponding to this dtype's resolution.
717720
"""
718721
reso = {
719-
"s": dtypes.NpyDatetimeUnit.NPY_FR_s,
720-
"ms": dtypes.NpyDatetimeUnit.NPY_FR_ms,
721-
"us": dtypes.NpyDatetimeUnit.NPY_FR_us,
722-
"ns": dtypes.NpyDatetimeUnit.NPY_FR_ns,
722+
"s": NpyDatetimeUnit.NPY_FR_s,
723+
"ms": NpyDatetimeUnit.NPY_FR_ms,
724+
"us": NpyDatetimeUnit.NPY_FR_us,
725+
"ns": NpyDatetimeUnit.NPY_FR_ns,
723726
}[self.unit]
724727
return reso.value
725728

@@ -820,7 +823,7 @@ def __setstate__(self, state) -> None:
820823

821824

822825
@register_extension_dtype
823-
class PeriodDtype(dtypes.PeriodDtypeBase, PandasExtensionDtype):
826+
class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
824827
"""
825828
An ExtensionDtype for Period data.
826829
@@ -869,7 +872,7 @@ def __new__(cls, freq=None):
869872
elif freq is None:
870873
# empty constructor for pickle compat
871874
# -10_000 corresponds to PeriodDtypeCode.UNDEFINED
872-
u = dtypes.PeriodDtypeBase.__new__(cls, -10_000)
875+
u = PeriodDtypeBase.__new__(cls, -10_000)
873876
u._freq = None
874877
return u
875878

@@ -880,7 +883,7 @@ def __new__(cls, freq=None):
880883
return cls._cache_dtypes[freq.freqstr]
881884
except KeyError:
882885
dtype_code = freq._period_dtype_code
883-
u = dtypes.PeriodDtypeBase.__new__(cls, dtype_code)
886+
u = PeriodDtypeBase.__new__(cls, dtype_code)
884887
u._freq = freq
885888
cls._cache_dtypes[freq.freqstr] = u
886889
return u

pandas/core/indexes/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137

138138
from pandas.core import (
139139
arraylike,
140-
missing,
141140
ops,
142141
)
143142
from pandas.core.accessor import CachedAccessor
@@ -163,6 +162,7 @@
163162
)
164163
from pandas.core.indexers import disallow_ndim_indexing
165164
from pandas.core.indexes.frozen import FrozenList
165+
from pandas.core.missing import clean_reindex_fill_method
166166
from pandas.core.ops import get_op_result_name
167167
from pandas.core.ops.invalid import make_invalid_op
168168
from pandas.core.sorting import (
@@ -3650,7 +3650,7 @@ def get_indexer(
36503650
limit: int | None = None,
36513651
tolerance=None,
36523652
) -> npt.NDArray[np.intp]:
3653-
method = missing.clean_reindex_fill_method(method)
3653+
method = clean_reindex_fill_method(method)
36543654
orig_target = target
36553655
target = self._maybe_cast_listlike_indexer(target)
36563656

0 commit comments

Comments
 (0)