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 2 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
30 changes: 15 additions & 15 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from __future__ import annotations

from datetime import (
datetime,
timedelta,
datetime as datetime_func,
timedelta as timedelta_func,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would import datetime as dt (and then dt.datetime, dt.timedelta) work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good.

import functools
from typing import (
Expand Down Expand Up @@ -73,7 +73,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 +170,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, datetime_func)):
value = Timestamp(value)
elif isinstance(value, (np.timedelta64, timedelta)):
elif isinstance(value, (np.timedelta64, timedelta_func)):
value = Timedelta(value)

return value
Expand Down Expand Up @@ -761,7 +761,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, datetime_func)):
try:
val = Timestamp(val)
except OutOfBoundsDatetime:
Expand All @@ -781,7 +781,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, timedelta_func)):
try:
val = Timedelta(val)
except (OutOfBoundsTimedelta, OverflowError):
Expand Down Expand Up @@ -1096,10 +1096,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 +1128,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 +1146,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 +1578,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, datetime_func):
# we dont want to box dt64, in particular datetime64("NaT")
value = maybe_box_datetimelike(value, dtype)

Expand Down
17 changes: 9 additions & 8 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
from pandas._libs import missing as libmissing
from pandas._libs.interval import Interval
from pandas._libs.properties import cache_readonly
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
from pandas._libs.tslibs.dtypes import PeriodDtypeBase
from pandas._libs.tslibs import (
BaseOffset,
NaT,
NaTType,
Period,
Timestamp,
dtypes,
timezones,
to_offset,
tz_compare,
Expand Down Expand Up @@ -716,10 +717,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 +821,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 +870,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 +881,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
5 changes: 2 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@
is_valid_na_for_dtype,
isna,
)

from pandas.core import (
missing as missing_func,
arraylike,
missing,
ops,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing isn't a function, so missing_func wouldn't be the best name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the issue with what you had before (from pandas.core.missing import clean_reindex_fill_method)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build pipeline failed at https://github.com/pandas-dev/pandas/actions/runs/3452096357/jobs/5761771671 which is failing still with missing_func. from pandas.core.missing import clean_reindex_fill_method worked locally but since pipeline failed , chaged it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was fine, you just need to run pre-commit on the files you've changed, check the contributing guide for how to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks did run it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, should be good now thanks

from pandas.core.accessor import CachedAccessor
Expand Down Expand Up @@ -3650,7 +3649,7 @@ def get_indexer(
limit: int | None = None,
tolerance=None,
) -> npt.NDArray[np.intp]:
method = missing.clean_reindex_fill_method(method)
method = missing_func.clean_reindex_fill_method(method)
orig_target = target
target = self._maybe_cast_listlike_indexer(target)

Expand Down