Skip to content

Commit 4ca451e

Browse files
MarcoGorelliKevin D Smith
authored and
Kevin D Smith
committed
CLN Upgrade pandas/core syntax (pandas-dev#36453)
1 parent 04e245b commit 4ca451e

File tree

11 files changed

+18
-36
lines changed

11 files changed

+18
-36
lines changed

pandas/core/arrays/datetimes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ def __iter__(self):
570570
converted = ints_to_pydatetime(
571571
data[start_i:end_i], tz=self.tz, freq=self.freq, box="timestamp"
572572
)
573-
for v in converted:
574-
yield v
573+
yield from converted
575574

576575
def astype(self, dtype, copy=True):
577576
# We handle

pandas/core/arrays/sparse/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ def sparse_arithmetic_method(self, other):
14271427
# TODO: look into _wrap_result
14281428
if len(self) != len(other):
14291429
raise AssertionError(
1430-
(f"length mismatch: {len(self)} vs. {len(other)}")
1430+
f"length mismatch: {len(self)} vs. {len(other)}"
14311431
)
14321432
if not isinstance(other, SparseArray):
14331433
dtype = getattr(other, "dtype", None)

pandas/core/common.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def flatten(l):
6262
"""
6363
for el in l:
6464
if iterable_not_string(el):
65-
for s in flatten(el):
66-
yield s
65+
yield from flatten(el)
6766
else:
6867
yield el
6968

@@ -434,10 +433,8 @@ def random_state(state=None):
434433
return np.random
435434
else:
436435
raise ValueError(
437-
(
438-
"random_state must be an integer, array-like, a BitGenerator, "
439-
"a numpy RandomState, or None"
440-
)
436+
"random_state must be an integer, array-like, a BitGenerator, "
437+
"a numpy RandomState, or None"
441438
)
442439

443440

pandas/core/computation/expr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _preparse(
153153
the ``tokenize`` module and ``tokval`` is a string.
154154
"""
155155
assert callable(f), "f must be callable"
156-
return tokenize.untokenize((f(x) for x in tokenize_string(source)))
156+
return tokenize.untokenize(f(x) for x in tokenize_string(source))
157157

158158

159159
def _is_type(t):

pandas/core/computation/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def __init__(
554554
else:
555555
w = _validate_where(w)
556556
where[idx] = w
557-
_where = " & ".join((f"({w})" for w in com.flatten(where)))
557+
_where = " & ".join(f"({w})" for w in com.flatten(where))
558558
else:
559559
_where = where
560560

pandas/core/generic.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1681,10 +1681,7 @@ def _get_label_or_level_values(self, key: str, axis: int = 0) -> np.ndarray:
16811681

16821682
label_axis_name = "column" if axis == 0 else "index"
16831683
raise ValueError(
1684-
(
1685-
f"The {label_axis_name} label '{key}' "
1686-
f"is not unique.{multi_message}"
1687-
)
1684+
f"The {label_axis_name} label '{key}' is not unique.{multi_message}"
16881685
)
16891686

16901687
return values
@@ -1725,10 +1722,8 @@ def _drop_labels_or_levels(self, keys, axis: int = 0):
17251722

17261723
if invalid_keys:
17271724
raise ValueError(
1728-
(
1729-
"The following keys are not valid labels or "
1730-
f"levels for axis {axis}: {invalid_keys}"
1731-
)
1725+
"The following keys are not valid labels or "
1726+
f"levels for axis {axis}: {invalid_keys}"
17321727
)
17331728

17341729
# Compute levels and labels to drop

pandas/core/groupby/base.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,8 @@ def _gotitem(self, key, ndim, subset=None):
9393
)
9494

9595
series_apply_allowlist = (
96-
(
97-
common_apply_allowlist
98-
| {
99-
"nlargest",
100-
"nsmallest",
101-
"is_monotonic_increasing",
102-
"is_monotonic_decreasing",
103-
}
104-
)
96+
common_apply_allowlist
97+
| {"nlargest", "nsmallest", "is_monotonic_increasing", "is_monotonic_decreasing"}
10598
) | frozenset(["dtype", "unique"])
10699

107100
dataframe_apply_allowlist = common_apply_allowlist | frozenset(["dtypes", "corrwith"])

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
12121212
return result
12131213

12141214
else:
1215-
all_indexed_same = all_indexes_same((x.index for x in values))
1215+
all_indexed_same = all_indexes_same(x.index for x in values)
12161216

12171217
# GH3596
12181218
# provide a reduction (Frame -> Series) if groups are

pandas/core/indexes/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def _maybe_check_unique(self):
504504
if not self.is_unique:
505505
msg = """Index has duplicates."""
506506
duplicates = self._format_duplicate_message()
507-
msg += "\n{}".format(duplicates)
507+
msg += f"\n{duplicates}"
508508

509509
raise DuplicateLabelError(msg)
510510

@@ -4315,10 +4315,8 @@ def identical(self, other) -> bool:
43154315
return (
43164316
self.equals(other)
43174317
and all(
4318-
(
4319-
getattr(self, c, None) == getattr(other, c, None)
4320-
for c in self._comparables
4321-
)
4318+
getattr(self, c, None) == getattr(other, c, None)
4319+
for c in self._comparables
43224320
)
43234321
and type(self) == type(other)
43244322
)

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _partial_date_slice(
398398

399399
if len(self) and (
400400
(use_lhs and t1 < self[0] and t2 < self[0])
401-
or ((use_rhs and t1 > self[-1] and t2 > self[-1]))
401+
or (use_rhs and t1 > self[-1] and t2 > self[-1])
402402
):
403403
# we are out of range
404404
raise KeyError

pandas/core/reshape/merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ def _get_single_indexer(join_key, index, sort: bool = False):
18371837
def _left_join_on_index(left_ax: Index, right_ax: Index, join_keys, sort: bool = False):
18381838
if len(join_keys) > 1:
18391839
if not (
1840-
(isinstance(right_ax, MultiIndex) and len(join_keys) == right_ax.nlevels)
1840+
isinstance(right_ax, MultiIndex) and len(join_keys) == right_ax.nlevels
18411841
):
18421842
raise AssertionError(
18431843
"If more than one join key is given then "

0 commit comments

Comments
 (0)