Skip to content

Commit a5eea36

Browse files
committed
STYLE: fix pylint redefined-outer-name warnings (#49656)
Fixed warnings for the following files :- - pandas/core/arrays/datetimelike.py - pandas/core/base.py - pandas/core/computation/pytables.py
1 parent 289f32d commit a5eea36

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

pandas/core/arrays/datetimelike.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,10 @@
112112
)
113113

114114
from pandas.core import (
115+
algorithms,
115116
nanops,
116117
ops,
117118
)
118-
from pandas.core.algorithms import (
119-
checked_add_with_arr,
120-
isin,
121-
mode,
122-
unique1d,
123-
)
124119
from pandas.core.arraylike import OpsMixin
125120
from pandas.core.arrays._mixins import (
126121
NDArrayBackedExtensionArray,
@@ -805,14 +800,14 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
805800
pass
806801

807802
elif "mixed" in inferred:
808-
return isin(self.astype(object), values)
803+
return algos.isin(self.astype(object), values)
809804
else:
810805
return np.zeros(self.shape, dtype=bool)
811806

812807
try:
813808
values = type(self)._from_sequence(values)
814809
except ValueError:
815-
return isin(self.astype(object), values)
810+
return algos.isin(self.astype(object), values)
816811

817812
if self.dtype.kind in ["m", "M"]:
818813
self = cast("DatetimeArray | TimedeltaArray", self)
@@ -824,7 +819,7 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
824819
# Includes tzawareness mismatch and IncompatibleFrequencyError
825820
return np.zeros(self.shape, dtype=bool)
826821

827-
return isin(self.asi8, values.asi8)
822+
return algos.isin(self.asi8, values.asi8)
828823

829824
# ------------------------------------------------------------------
830825
# Null Handling
@@ -993,7 +988,7 @@ def _is_monotonic_decreasing(self) -> bool:
993988

994989
@property
995990
def _is_unique(self) -> bool:
996-
return len(unique1d(self.asi8.ravel("K"))) == self.size
991+
return len(algos.unique1d(self.asi8.ravel("K"))) == self.size
997992

998993
# ------------------------------------------------------------------
999994
# Arithmetic Methods
@@ -1125,7 +1120,7 @@ def _add_datetimelike_scalar(self, other) -> DatetimeArray:
11251120
self = cast("TimedeltaArray", self)
11261121

11271122
other_i8, o_mask = self._get_i8_values_and_mask(other)
1128-
result = checked_add_with_arr(
1123+
result = algos.checked_add_with_arr(
11291124
self.asi8, other_i8, arr_mask=self._isnan, b_mask=o_mask
11301125
)
11311126
res_values = result.view(f"M8[{self.unit}]")
@@ -1188,7 +1183,7 @@ def _sub_datetimelike(self, other: Timestamp | DatetimeArray) -> TimedeltaArray:
11881183
raise type(err)(new_message) from err
11891184

11901185
other_i8, o_mask = self._get_i8_values_and_mask(other)
1191-
res_values = checked_add_with_arr(
1186+
res_values = algos.checked_add_with_arr(
11921187
self.asi8, -other_i8, arr_mask=self._isnan, b_mask=o_mask
11931188
)
11941189
res_m8 = res_values.view(f"timedelta64[{self.unit}]")
@@ -1254,7 +1249,7 @@ def _add_timedeltalike(self, other: Timedelta | TimedeltaArray):
12541249
self = cast("DatetimeArray | TimedeltaArray", self)
12551250

12561251
other_i8, o_mask = self._get_i8_values_and_mask(other)
1257-
new_values = checked_add_with_arr(
1252+
new_values = algos.checked_add_with_arr(
12581253
self.asi8, other_i8, arr_mask=self._isnan, b_mask=o_mask
12591254
)
12601255
res_values = new_values.view(self._ndarray.dtype)
@@ -1309,7 +1304,7 @@ def _sub_periodlike(self, other: Period | PeriodArray) -> npt.NDArray[np.object_
13091304
self._check_compatible_with(other)
13101305

13111306
other_i8, o_mask = self._get_i8_values_and_mask(other)
1312-
new_i8_data = checked_add_with_arr(
1307+
new_i8_data = algos.checked_add_with_arr(
13131308
self.asi8, -other_i8, arr_mask=self._isnan, b_mask=o_mask
13141309
)
13151310
new_data = np.array([self.freq.base * x for x in new_i8_data])
@@ -1690,7 +1685,7 @@ def _mode(self, dropna: bool = True):
16901685
if dropna:
16911686
mask = self.isna()
16921687

1693-
i8modes = mode(self.view("i8"), mask=mask)
1688+
i8modes = algorithms.algos.mode(self.view("i8"), mask=mask)
16941689
npmodes = i8modes.view(self._ndarray.dtype)
16951690
npmodes = cast(np.ndarray, npmodes)
16961691
return self._from_backing_data(npmodes)

pandas/core/base.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@
6161
ops,
6262
)
6363
from pandas.core.accessor import DirNamesMixin
64-
from pandas.core.algorithms import (
65-
duplicated,
66-
unique1d,
67-
value_counts,
68-
)
64+
from pandas.core.algorithms import algos
65+
66+
# from pandas.core.algorithms import (
67+
# duplicated as duplicated_func,
68+
# unique1d,
69+
# value_counts,
70+
# )
6971
from pandas.core.arraylike import OpsMixin
7072
from pandas.core.arrays import ExtensionArray
7173
from pandas.core.construction import (
@@ -991,7 +993,7 @@ def value_counts(
991993
NaN 1
992994
dtype: int64
993995
"""
994-
return value_counts(
996+
return algos.value_counts(
995997
self,
996998
sort=sort,
997999
ascending=ascending,
@@ -1006,7 +1008,7 @@ def unique(self):
10061008
# i.e. ExtensionArray
10071009
result = values.unique()
10081010
else:
1009-
result = unique1d(values)
1011+
result = algos.unique1d(values)
10101012
return result
10111013

10121014
@final
@@ -1294,7 +1296,7 @@ def drop_duplicates(self, *, keep: DropKeep = "first"):
12941296

12951297
@final
12961298
def _duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]:
1297-
return duplicated(self._values, keep=keep)
1299+
return algos.duplicated(self._values, keep=keep)
12981300

12991301
def _arith_method(self, other, op):
13001302
res_name = ops.get_op_result_name(self, other)

pandas/core/computation/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def maybe_expression(s) -> bool:
650650
"""loose checking if s is a pytables-acceptable expression"""
651651
if not isinstance(s, str):
652652
return False
653-
ops = PyTablesExprVisitor.binary_ops + PyTablesExprVisitor.unary_ops + ("=",)
653+
operations = PyTablesExprVisitor.binary_ops + PyTablesExprVisitor.unary_ops + ("=",)
654654

655655
# make sure we have an op at least
656-
return any(op in s for op in ops)
656+
return any(op in s for op in operations)

0 commit comments

Comments
 (0)