Skip to content

CLN Upgrade pandas/core syntax #36453

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 2 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,7 @@ def __iter__(self):
converted = ints_to_pydatetime(
data[start_i:end_i], tz=self.tz, freq=self.freq, box="timestamp"
)
for v in converted:
yield v
yield from converted

def astype(self, dtype, copy=True):
# We handle
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ def sparse_arithmetic_method(self, other):
# TODO: look into _wrap_result
if len(self) != len(other):
raise AssertionError(
(f"length mismatch: {len(self)} vs. {len(other)}")
f"length mismatch: {len(self)} vs. {len(other)}"
)
if not isinstance(other, SparseArray):
dtype = getattr(other, "dtype", None)
Expand Down
9 changes: 3 additions & 6 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def flatten(l):
"""
for el in l:
if iterable_not_string(el):
for s in flatten(el):
yield s
yield from flatten(el)
else:
yield el

Expand Down Expand Up @@ -434,10 +433,8 @@ def random_state(state=None):
return np.random
else:
raise ValueError(
(
"random_state must be an integer, array-like, a BitGenerator, "
"a numpy RandomState, or None"
)
"random_state must be an integer, array-like, a BitGenerator, "
"a numpy RandomState, or None"
)


Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _preparse(
the ``tokenize`` module and ``tokval`` is a string.
"""
assert callable(f), "f must be callable"
return tokenize.untokenize((f(x) for x in tokenize_string(source)))
return tokenize.untokenize(f(x) for x in tokenize_string(source))


def _is_type(t):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def __init__(
else:
w = _validate_where(w)
where[idx] = w
_where = " & ".join((f"({w})" for w in com.flatten(where)))
_where = " & ".join(f"({w})" for w in com.flatten(where))
else:
_where = where

Expand Down
11 changes: 3 additions & 8 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,10 +1681,7 @@ def _get_label_or_level_values(self, key: str, axis: int = 0) -> np.ndarray:

label_axis_name = "column" if axis == 0 else "index"
raise ValueError(
(
f"The {label_axis_name} label '{key}' "
f"is not unique.{multi_message}"
)
f"The {label_axis_name} label '{key}' is not unique.{multi_message}"
)

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

if invalid_keys:
raise ValueError(
(
"The following keys are not valid labels or "
f"levels for axis {axis}: {invalid_keys}"
)
"The following keys are not valid labels or "
f"levels for axis {axis}: {invalid_keys}"
)

# Compute levels and labels to drop
Expand Down
11 changes: 2 additions & 9 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,8 @@ def _gotitem(self, key, ndim, subset=None):
)

series_apply_allowlist = (
(
common_apply_allowlist
| {
"nlargest",
"nsmallest",
"is_monotonic_increasing",
"is_monotonic_decreasing",
}
)
common_apply_allowlist
| {"nlargest", "nsmallest", "is_monotonic_increasing", "is_monotonic_decreasing"}
) | frozenset(["dtype", "unique"])

dataframe_apply_allowlist = common_apply_allowlist | frozenset(["dtypes", "corrwith"])
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
return result

else:
all_indexed_same = all_indexes_same((x.index for x in values))
all_indexed_same = all_indexes_same(x.index for x in values)

# GH3596
# provide a reduction (Frame -> Series) if groups are
Expand Down
8 changes: 3 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def _maybe_check_unique(self):
if not self.is_unique:
msg = """Index has duplicates."""
duplicates = self._format_duplicate_message()
msg += "\n{}".format(duplicates)
msg += f"\n{duplicates}"

raise DuplicateLabelError(msg)

Expand Down Expand Up @@ -4315,10 +4315,8 @@ def identical(self, other) -> bool:
return (
self.equals(other)
and all(
(
getattr(self, c, None) == getattr(other, c, None)
for c in self._comparables
)
getattr(self, c, None) == getattr(other, c, None)
for c in self._comparables
)
and type(self) == type(other)
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def _partial_date_slice(

if len(self) and (
(use_lhs and t1 < self[0] and t2 < self[0])
or ((use_rhs and t1 > self[-1] and t2 > self[-1]))
or (use_rhs and t1 > self[-1] and t2 > self[-1])
):
# we are out of range
raise KeyError
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ def _get_single_indexer(join_key, index, sort: bool = False):
def _left_join_on_index(left_ax: Index, right_ax: Index, join_keys, sort: bool = False):
if len(join_keys) > 1:
if not (
(isinstance(right_ax, MultiIndex) and len(join_keys) == right_ax.nlevels)
isinstance(right_ax, MultiIndex) and len(join_keys) == right_ax.nlevels
):
raise AssertionError(
"If more than one join key is given then "
Expand Down