Skip to content

Commit 8d4cab5

Browse files
authored
STYLE: turn off PLW2901 (but keep some changes) (#52262)
* Removed unnecessary code * Enabled PLW2901 on initial files under pandas/core/* * Divided pandas/core/* in pyproject.toml. Included some more fixes. * Not sure why but the call to partial removes the .__name__ attribute to aggfunc if just returned. * Ignored type checker and corrected possible induced bug in period.py * Forgot to add the not in previous commit * Reverted changes and updated pyproject.toml * turn off redefined-loop-variable, minimise diff * revert fun_name change --------- Co-authored-by: MarcoGorelli <>
1 parent 6480090 commit 8d4cab5

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

pandas/core/arrays/period.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,10 @@ def _range_from_fields(
11241124
freqstr = freq.freqstr
11251125
year, quarter = _make_field_arrays(year, quarter)
11261126
for y, q in zip(year, quarter):
1127-
y, m = parsing.quarter_to_myear(y, q, freqstr)
1128-
val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
1127+
calendar_year, calendar_month = parsing.quarter_to_myear(y, q, freqstr)
1128+
val = libperiod.period_ordinal(
1129+
calendar_year, calendar_month, 1, 1, 1, 1, 0, 0, base
1130+
)
11291131
ordinals.append(val)
11301132
else:
11311133
freq = to_offset(freq)

pandas/core/computation/pytables.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ def __init__(
568568
if isinstance(w, PyTablesExpr):
569569
local_dict = w.env.scope
570570
else:
571-
w = _validate_where(w)
572-
where[idx] = w
571+
where[idx] = _validate_where(w)
573572
_where = " & ".join([f"({w})" for w in com.flatten(where)])
574573
else:
575574
# _validate_where ensures we otherwise have a string

pandas/core/sorting.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ def maybe_lift(lab, size: int) -> tuple[np.ndarray, int]:
162162
lshape = list(shape)
163163
if not xnull:
164164
for i, (lab, size) in enumerate(zip(labels, shape)):
165-
lab, size = maybe_lift(lab, size)
166-
labels[i] = lab
167-
lshape[i] = size
165+
labels[i], lshape[i] = maybe_lift(lab, size)
168166

169167
labels = list(labels)
170168

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ ignore = [
266266
"PLR0912",
267267
# Too many statements
268268
"PLR0915",
269+
# Redefined loop name
270+
"PLW2901",
269271
# Global statements are discouraged
270272
"PLW0603",
271273
# Docstrings should not be included in stubs
@@ -302,10 +304,8 @@ exclude = [
302304
# relative imports allowed for asv_bench
303305
"asv_bench/*" = ["TID"]
304306
# to be enabled gradually
305-
"pandas/core/*" = ["PLR5501", "PLW2901"]
306-
"pandas/io/*" = ["PLW2901"]
307-
"pandas/tests/*" = ["B028", "PLW2901"]
308-
"pandas/plotting/*" = ["PLW2901"]
307+
"pandas/core/*" = ["PLR5501"]
308+
"pandas/tests/*" = ["B028"]
309309
"scripts/*" = ["B028"]
310310
# Keep this one enabled
311311
"pandas/_typing.py" = ["TCH"]
@@ -356,6 +356,7 @@ disable = [
356356
"use-implicit-booleaness-not-len",
357357
"wrong-import-order",
358358
"wrong-import-position",
359+
"redefined-loop-name",
359360

360361
# misc
361362
"abstract-class-instantiated",

scripts/validate_docstrings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,14 @@ def get_api_items(api_doc_fd):
130130
if line_stripped == "":
131131
position = None
132132
continue
133-
item = line_stripped.strip()
134-
if item in IGNORE_VALIDATION:
133+
if line_stripped in IGNORE_VALIDATION:
135134
continue
136135
func = importlib.import_module(current_module)
137-
for part in item.split("."):
136+
for part in line_stripped.split("."):
138137
func = getattr(func, part)
139138

140139
yield (
141-
".".join([current_module, item]),
140+
".".join([current_module, line_stripped]),
142141
func,
143142
current_section,
144143
current_subsection,

0 commit comments

Comments
 (0)