Skip to content

Commit 6e93f07

Browse files
committed
Enabled PLW2901 on initial files under pandas/core/*
1 parent 61fad93 commit 6e93f07

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

pandas/core/apply.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1379,10 +1379,10 @@ def relabel_result(
13791379
# mean 1.5
13801380
# mean 1.5
13811381
if reorder_mask:
1382-
fun = [
1382+
fun_name = [
13831383
com.get_callable_name(f) if not isinstance(f, str) else f for f in fun
13841384
]
1385-
col_idx_order = Index(s.index).get_indexer(fun)
1385+
col_idx_order = Index(s.index).get_indexer(fun_name)
13861386
s = s[col_idx_order]
13871387

13881388
# assign the new user-provided "named aggregation" as index names, and reindex
@@ -1421,14 +1421,16 @@ def _managle_lambda_list(aggfuncs: Sequence[Any]) -> Sequence[Any]:
14211421
if len(aggfuncs) <= 1:
14221422
# don't mangle for .agg([lambda x: .])
14231423
return aggfuncs
1424-
i = 0
1424+
14251425
mangled_aggfuncs = []
1426-
for aggfunc in aggfuncs:
1427-
if com.get_callable_name(aggfunc) == "<lambda>":
1428-
aggfunc = partial(aggfunc)
1429-
aggfunc.__name__ = f"<lambda_{i}>"
1430-
i += 1
1431-
mangled_aggfuncs.append(aggfunc)
1426+
for idx, aggfunc in enumerate(aggfuncs):
1427+
if not com.get_callable_name(aggfunc) == "<lambda>":
1428+
mangled_aggfuncs.append(aggfunc)
1429+
continue
1430+
1431+
partial_aggfunc = partial(aggfunc)
1432+
partial_aggfunc.__name__ = f"<lambda_{idx}>"
1433+
mangled_aggfuncs.append(partial_aggfunc)
14321434

14331435
return mangled_aggfuncs
14341436

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def _range_from_fields(
10991099
freqstr = freq.freqstr
11001100
year, quarter = _make_field_arrays(year, quarter)
11011101
for y, q in zip(year, quarter):
1102-
y, m = parsing.quarter_to_myear(y, q, freqstr)
1102+
_, m = parsing.quarter_to_myear(y, q, freqstr)
11031103
val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
11041104
ordinals.append(val)
11051105
else:

pandas/core/computation/eval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def eval(
320320
first_expr = True
321321
target_modified = False
322322

323-
for expr in exprs:
324-
expr = _convert_expression(expr)
323+
for expr_obj in exprs:
324+
expr = _convert_expression(expr_obj)
325325
_check_for_locals(expr, level, parser)
326326

327327
# get our (possibly passed-in) scope

pandas/core/computation/pytables.py

+1-2
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/dtypes/dtypes.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1267,9 +1267,11 @@ def __from_arrow__(
12671267
chunks = array.chunks
12681268

12691269
results = []
1270-
for arr in chunks:
1271-
if isinstance(arr, pyarrow.ExtensionArray):
1272-
arr = arr.storage
1270+
for arr_chunk in chunks:
1271+
arr = (
1272+
arr_chunk.storage if isinstance(arr_chunk, pyarrow.ExtensionArray)
1273+
else arr_chunk
1274+
)
12731275
left = np.asarray(arr.field("left"), dtype=self.subtype)
12741276
right = np.asarray(arr.field("right"), dtype=self.subtype)
12751277
iarr = IntervalArray.from_arrays(left, right, closed=self.closed)

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def _init_mgr(
292292
"""passed a manager and a axes dict"""
293293
for a, axe in axes.items():
294294
if axe is not None:
295-
axe = ensure_index(axe)
295+
axe_w_idx = ensure_index(axe)
296296
bm_axis = cls._get_block_manager_axis(a)
297-
mgr = mgr.reindex_axis(axe, axis=bm_axis)
297+
mgr = mgr.reindex_axis(axe_w_idx, axis=bm_axis)
298298

299299
# make a copy if explicitly requested
300300
if copy:

0 commit comments

Comments
 (0)