Skip to content

STYLE enable pylint's redefined-outer-name #49671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

from __future__ import annotations

from datetime import (
datetime,
timedelta,
)
import datetime as dt
import functools
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -73,7 +70,7 @@
is_string_dtype,
is_timedelta64_dtype,
is_unsigned_integer_dtype,
pandas_dtype,
pandas_dtype as pandas_dtype_func,
)
from pandas.core.dtypes.dtypes import (
CategoricalDtype,
Expand Down Expand Up @@ -170,9 +167,9 @@ def maybe_box_datetimelike(value: Scalar, dtype: Dtype | None = None) -> Scalar:
"""
if dtype == _dtype_obj:
pass
elif isinstance(value, (np.datetime64, datetime)):
elif isinstance(value, (np.datetime64, dt.datetime)):
value = Timestamp(value)
elif isinstance(value, (np.timedelta64, timedelta)):
elif isinstance(value, (np.timedelta64, dt.timedelta)):
value = Timedelta(value)

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

dtype = _dtype_obj

elif isinstance(val, (np.datetime64, datetime)):
elif isinstance(val, (np.datetime64, dt.datetime)):
try:
val = Timestamp(val)
except OutOfBoundsDatetime:
Expand All @@ -781,7 +778,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
# return datetimetz as object
return _dtype_obj, val

elif isinstance(val, (np.timedelta64, timedelta)):
elif isinstance(val, (np.timedelta64, dt.timedelta)):
try:
val = Timedelta(val)
except (OutOfBoundsTimedelta, OverflowError):
Expand Down Expand Up @@ -1096,10 +1093,10 @@ def convert_dtypes(
if not convert_string or inferred_dtype == "bytes":
return input_array.dtype
else:
return pandas_dtype("string")
return pandas_dtype_func("string")

if convert_integer:
target_int_dtype = pandas_dtype("Int64")
target_int_dtype = pandas_dtype_func("Int64")

if is_integer_dtype(input_array.dtype):
from pandas.core.arrays.integer import INT_STR_TO_DTYPE
Expand Down Expand Up @@ -1128,15 +1125,15 @@ def convert_dtypes(
from pandas.core.arrays.floating import FLOAT_STR_TO_DTYPE

inferred_float_dtype: DtypeObj = FLOAT_STR_TO_DTYPE.get(
input_array.dtype.name, pandas_dtype("Float64")
input_array.dtype.name, pandas_dtype_func("Float64")
)
# if we could also convert to integer, check if all floats
# are actually integers
if convert_integer:
# TODO: de-dup with maybe_cast_to_integer_array?
arr = input_array[notna(input_array)]
if (arr.astype(int) == arr).all():
inferred_dtype = pandas_dtype("Int64")
inferred_dtype = pandas_dtype_func("Int64")
else:
inferred_dtype = inferred_float_dtype
else:
Expand All @@ -1146,13 +1143,13 @@ def convert_dtypes(
and is_object_dtype(input_array.dtype)
and inferred_dtype == "mixed-integer-float"
):
inferred_dtype = pandas_dtype("Float64")
inferred_dtype = pandas_dtype_func("Float64")

if convert_boolean:
if is_bool_dtype(input_array.dtype):
inferred_dtype = pandas_dtype("boolean")
inferred_dtype = pandas_dtype_func("boolean")
elif isinstance(inferred_dtype, str) and inferred_dtype == "boolean":
inferred_dtype = pandas_dtype("boolean")
inferred_dtype = pandas_dtype_func("boolean")

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

if isinstance(value, datetime):
if isinstance(value, dt.datetime):
# we dont want to box dt64, in particular datetime64("NaT")
value = maybe_box_datetimelike(value, dtype)

Expand Down
19 changes: 11 additions & 8 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
NaTType,
Period,
Timestamp,
dtypes,
timezones,
to_offset,
tz_compare,
)
from pandas._libs.tslibs.dtypes import (
NpyDatetimeUnit,
PeriodDtypeBase,
)
from pandas._typing import (
Dtype,
DtypeObj,
Expand Down Expand Up @@ -716,10 +719,10 @@ def _creso(self) -> int:
The NPY_DATETIMEUNIT corresponding to this dtype's resolution.
"""
reso = {
"s": dtypes.NpyDatetimeUnit.NPY_FR_s,
"ms": dtypes.NpyDatetimeUnit.NPY_FR_ms,
"us": dtypes.NpyDatetimeUnit.NPY_FR_us,
"ns": dtypes.NpyDatetimeUnit.NPY_FR_ns,
"s": NpyDatetimeUnit.NPY_FR_s,
"ms": NpyDatetimeUnit.NPY_FR_ms,
"us": NpyDatetimeUnit.NPY_FR_us,
"ns": NpyDatetimeUnit.NPY_FR_ns,
}[self.unit]
return reso.value

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


@register_extension_dtype
class PeriodDtype(dtypes.PeriodDtypeBase, PandasExtensionDtype):
class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
"""
An ExtensionDtype for Period data.

Expand Down Expand Up @@ -869,7 +872,7 @@ def __new__(cls, freq=None):
elif freq is None:
# empty constructor for pickle compat
# -10_000 corresponds to PeriodDtypeCode.UNDEFINED
u = dtypes.PeriodDtypeBase.__new__(cls, -10_000)
u = PeriodDtypeBase.__new__(cls, -10_000)
u._freq = None
return u

Expand All @@ -880,7 +883,7 @@ def __new__(cls, freq=None):
return cls._cache_dtypes[freq.freqstr]
except KeyError:
dtype_code = freq._period_dtype_code
u = dtypes.PeriodDtypeBase.__new__(cls, dtype_code)
u = PeriodDtypeBase.__new__(cls, dtype_code)
u._freq = freq
cls._cache_dtypes[freq.freqstr] = u
return u
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@

from pandas.core import (
arraylike,
missing,
ops,
)
from pandas.core.accessor import CachedAccessor
Expand All @@ -163,6 +162,7 @@
)
from pandas.core.indexers import disallow_ndim_indexing
from pandas.core.indexes.frozen import FrozenList
from pandas.core.missing import clean_reindex_fill_method
from pandas.core.ops import get_op_result_name
from pandas.core.ops.invalid import make_invalid_op
from pandas.core.sorting import (
Expand Down Expand Up @@ -3650,7 +3650,7 @@ def get_indexer(
limit: int | None = None,
tolerance=None,
) -> npt.NDArray[np.intp]:
method = missing.clean_reindex_fill_method(method)
method = clean_reindex_fill_method(method)
orig_target = target
target = self._maybe_cast_listlike_indexer(target)

Expand Down