Skip to content

Commit 042ebab

Browse files
authored
STY: Enable ruff C4 - comprehensions (#53056)
* STY: Enable ruff C4 - comprehensions * Revert one
1 parent 3888179 commit 042ebab

File tree

22 files changed

+41
-42
lines changed

22 files changed

+41
-42
lines changed

asv_bench/benchmarks/dtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
class Dtypes:
27-
params = _dtypes + list(map(lambda dt: dt.name, _dtypes))
27+
params = _dtypes + [dt.name for dt in _dtypes]
2828
param_names = ["dtype"]
2929

3030
def time_pandas_dtype(self, dtype):

pandas/core/computation/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def _filter_nodes(superclass, all_nodes=_all_nodes):
192192
return frozenset(node_names)
193193

194194

195-
_all_node_names = frozenset(map(lambda x: x.__name__, _all_nodes))
195+
_all_node_names = frozenset(x.__name__ for x in _all_nodes)
196196
_mod_nodes = _filter_nodes(ast.mod)
197197
_stmt_nodes = _filter_nodes(ast.stmt)
198198
_expr_nodes = _filter_nodes(ast.expr)

pandas/core/groupby/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4115,9 +4115,9 @@ def _reindex_output(
41154115
# reindex `output`, and then reset the in-axis grouper columns.
41164116

41174117
# Select in-axis groupers
4118-
in_axis_grps = list(
4118+
in_axis_grps = [
41194119
(i, ping.name) for (i, ping) in enumerate(groupings) if ping.in_axis
4120-
)
4120+
]
41214121
if len(in_axis_grps) > 0:
41224122
g_nums, g_names = zip(*in_axis_grps)
41234123
output = output.drop(labels=list(g_names), axis=1)

pandas/io/formats/excel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def _format_header(self) -> Iterable[ExcelCell]:
726726
row = [x if x is not None else "" for x in self.df.index.names] + [
727727
""
728728
] * len(self.columns)
729-
if reduce(lambda x, y: x and y, map(lambda x: x != "", row)):
729+
if reduce(lambda x, y: x and y, (x != "" for x in row)):
730730
gen2 = (
731731
ExcelCell(self.rowcounter, colindex, val, self.header_style)
732732
for colindex, val in enumerate(row)

pandas/io/formats/html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def write_style(self) -> None:
621621
)
622622
else:
623623
element_props.append(("thead th", "text-align", "right"))
624-
template_mid = "\n\n".join(map(lambda t: template_select % t, element_props))
624+
template_mid = "\n\n".join(template_select % t for t in element_props)
625625
template = dedent("\n".join((template_first, template_mid, template_last)))
626626
self.write(template)
627627

pandas/tests/computation/test_eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_compound_invert_op(self, op, lhs, rhs, request, engine, parser):
218218
else:
219219
# compound
220220
if is_scalar(lhs) and is_scalar(rhs):
221-
lhs, rhs = map(lambda x: np.array([x]), (lhs, rhs))
221+
lhs, rhs = (np.array([x]) for x in (lhs, rhs))
222222
expected = _eval_single_bin(lhs, op, rhs, engine)
223223
if is_scalar(expected):
224224
expected = not expected
@@ -746,7 +746,7 @@ def test_binop_typecasting(self, engine, parser, op, dt, left_right):
746746
def should_warn(*args):
747747
not_mono = not any(map(operator.attrgetter("is_monotonic_increasing"), args))
748748
only_one_dt = reduce(
749-
operator.xor, map(lambda x: issubclass(x.dtype.type, np.datetime64), args)
749+
operator.xor, (issubclass(x.dtype.type, np.datetime64) for x in args)
750750
)
751751
return not_mono and only_one_dt
752752

pandas/tests/dtypes/test_missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def test_array_equivalent_nested_mixed_list(strict_nan):
643643
np.array(["c", "d"], dtype=object),
644644
]
645645
left = np.array([subarr, None], dtype=object)
646-
right = np.array([list([[None, "b"], ["c", "d"]]), None], dtype=object)
646+
right = np.array([[[None, "b"], ["c", "d"]], None], dtype=object)
647647
assert array_equivalent(left, right, strict_nan=strict_nan)
648648
assert not array_equivalent(left, right[::-1], strict_nan=strict_nan)
649649

pandas/tests/extension/date/array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
self._day = np.zeros(ldates, dtype=np.uint8) # 255 (1, 12)
8484
# populate them
8585
for i, (y, m, d) in enumerate(
86-
map(lambda date: (date.year, date.month, date.day), dates)
86+
(date.year, date.month, date.day) for date in dates
8787
):
8888
self._year[i] = y
8989
self._month[i] = m
@@ -94,7 +94,7 @@ def __init__(
9494
if ldates != 3:
9595
raise ValueError("only triples are valid")
9696
# check if all elements have the same type
97-
if any(map(lambda x: not isinstance(x, np.ndarray), dates)):
97+
if any(not isinstance(x, np.ndarray) for x in dates):
9898
raise TypeError("invalid type")
9999
ly, lm, ld = (len(cast(np.ndarray, d)) for d in dates)
100100
if not ly == lm == ld:

pandas/tests/frame/methods/test_astype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def test_astype_str(self):
152152

153153
expected = DataFrame(
154154
{
155-
"a": list(map(str, map(lambda x: Timestamp(x)._date_repr, a._values))),
155+
"a": list(map(str, (Timestamp(x)._date_repr for x in a._values))),
156156
"b": list(map(str, map(Timestamp, b._values))),
157-
"c": list(map(lambda x: Timedelta(x)._repr_base(), c._values)),
157+
"c": [Timedelta(x)._repr_base() for x in c._values],
158158
"d": list(map(str, d._values)),
159159
"e": list(map(str, e._values)),
160160
}

pandas/tests/groupby/test_grouping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ def test_multi_iter_frame(self, three_group):
992992
# calling `dict` on a DataFrameGroupBy leads to a TypeError,
993993
# we need to use a dictionary comprehension here
994994
# pylint: disable-next=unnecessary-comprehension
995-
groups = {key: gp for key, gp in grouped}
995+
groups = {key: gp for key, gp in grouped} # noqa: C416
996996
assert len(groups) == 2
997997

998998
# axis = 1

0 commit comments

Comments
 (0)