Skip to content

STYLE: turn off PLW2901 (but keep some changes) #52262

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 13 commits into from
Apr 12, 2023
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
20 changes: 11 additions & 9 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,10 +1379,10 @@ def relabel_result(
# mean 1.5
# mean 1.5
if reorder_mask:
fun = [
Copy link
Member

Choose a reason for hiding this comment

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

not sure we can do this, fun is still used below

fun_name = [
com.get_callable_name(f) if not isinstance(f, str) else f for f in fun
]
col_idx_order = Index(s.index).get_indexer(fun)
col_idx_order = Index(s.index).get_indexer(fun_name)
s = s[col_idx_order]

# assign the new user-provided "named aggregation" as index names, and reindex
Expand Down Expand Up @@ -1421,14 +1421,16 @@ def _managle_lambda_list(aggfuncs: Sequence[Any]) -> Sequence[Any]:
if len(aggfuncs) <= 1:
# don't mangle for .agg([lambda x: .])
return aggfuncs
i = 0

mangled_aggfuncs = []
for aggfunc in aggfuncs:
if com.get_callable_name(aggfunc) == "<lambda>":
aggfunc = partial(aggfunc)
aggfunc.__name__ = f"<lambda_{i}>"
i += 1
mangled_aggfuncs.append(aggfunc)
for idx, aggfunc in enumerate(aggfuncs):
if not com.get_callable_name(aggfunc) == "<lambda>":
mangled_aggfuncs.append(aggfunc)
continue

partial_aggfunc = partial(aggfunc)
partial_aggfunc.__name__ = f"<lambda_{idx}>"
Copy link
Member

Choose a reason for hiding this comment

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

also, I don't think the logic is right here, please try to keep the logic the same as the original

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 original one was:

i = 0
for aggfunc in aggfuncs:
        if com.get_callable_name(aggfunc) == "<lambda>":
            aggfunc = partial(aggfunc)
            aggfunc.__name__ = f"<lambda_{i}>"
            i += 1
        mangled_aggfuncs.append(aggfunc)

I removed the variable i, replacing it by idx generated by the call to enumerate. Then I inverted the if clause, making it a if not. In this way I can insert inside the condition the single line:
mangled_aggfuncs.append(aggfunc)
and then continue the loop. So I moved what was inside the if outside. Sorry I understand it's not super clear, but I thought would look nicer to have a lighter content inside the if statement. If you want I can revert the logic.

mangled_aggfuncs.append(partial_aggfunc)

return mangled_aggfuncs

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ def _range_from_fields(
freqstr = freq.freqstr
year, quarter = _make_field_arrays(year, quarter)
for y, q in zip(year, quarter):
y, m = parsing.quarter_to_myear(y, q, freqstr)
_, m = parsing.quarter_to_myear(y, q, freqstr)
val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't look right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, indeed the variable y can be changed inside the function quarter_to_myear. Updated! Thanks for the heads up!

ordinals.append(val)
else:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def eval(
first_expr = True
target_modified = False

for expr in exprs:
expr = _convert_expression(expr)
for expr_obj in exprs:
expr = _convert_expression(expr_obj)
_check_for_locals(expr, level, parser)

# get our (possibly passed-in) scope
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,7 @@ def __init__(
if isinstance(w, PyTablesExpr):
local_dict = w.env.scope
else:
w = _validate_where(w)
where[idx] = w
where[idx] = _validate_where(w)
_where = " & ".join([f"({w})" for w in com.flatten(where)])
else:
# _validate_where ensures we otherwise have a string
Expand Down
9 changes: 6 additions & 3 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,9 +1267,12 @@ def __from_arrow__(
chunks = array.chunks

results = []
for arr in chunks:
if isinstance(arr, pyarrow.ExtensionArray):
arr = arr.storage
for arr_chunk in chunks:
arr = (
arr_chunk.storage
if isinstance(arr_chunk, pyarrow.ExtensionArray)
else arr_chunk
)
left = np.asarray(arr.field("left"), dtype=self.subtype)
right = np.asarray(arr.field("right"), dtype=self.subtype)
iarr = IntervalArray.from_arrays(left, right, closed=self.closed)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def _init_mgr(
"""passed a manager and a axes dict"""
for a, axe in axes.items():
if axe is not None:
axe = ensure_index(axe)
axe_w_idx = ensure_index(axe)
bm_axis = cls._get_block_manager_axis(a)
mgr = mgr.reindex_axis(axe, axis=bm_axis)
mgr = mgr.reindex_axis(axe_w_idx, axis=bm_axis)

# make a copy if explicitly requested
if copy:
Expand Down
7 changes: 3 additions & 4 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ def get_api_items(api_doc_fd):
if line_stripped == "":
position = None
continue
item = line_stripped.strip()
if item in IGNORE_VALIDATION:
if line_stripped in IGNORE_VALIDATION:
continue
func = importlib.import_module(current_module)
for part in item.split("."):
for part in line_stripped.split("."):
func = getattr(func, part)

yield (
".".join([current_module, item]),
".".join([current_module, line_stripped]),
func,
current_section,
current_subsection,
Expand Down