From 54b2ef1e5959a607908f7d7dd635b0ac2523af5d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Sep 2024 03:05:08 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/toolzcompat.py | 3 ++- xarray/groupers.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/xarray/core/toolzcompat.py b/xarray/core/toolzcompat.py index 5eeb9681afc..4632419a845 100644 --- a/xarray/core/toolzcompat.py +++ b/xarray/core/toolzcompat.py @@ -51,5 +51,6 @@ def sliding_window(n, seq): *( collections.deque(itertools.islice(it, i), 0) or it for i, it in enumerate(itertools.tee(seq, n)) - ) + ), + strict=False, ) diff --git a/xarray/groupers.py b/xarray/groupers.py index 434bd764fa4..0ba59f726df 100644 --- a/xarray/groupers.py +++ b/xarray/groupers.py @@ -24,6 +24,7 @@ from xarray.core.groupby import T_Group, _DummyGroup from xarray.core.indexes import safe_cast_to_index from xarray.core.resample_cftime import CFTimeGrouper +from xarray.core.toolzcompat import sliding_window from xarray.core.types import ( Bins, DatetimeLike, @@ -31,7 +32,6 @@ ResampleCompatible, SideOptions, ) -from xarray.core.toolzcompat import sliding_window from xarray.core.variable import Variable __all__ = [ @@ -495,7 +495,7 @@ def season_to_month_tuple(seasons: Sequence[str]) -> tuple[tuple[int, ...], ...] initials = "JFMAMJJASOND" starts = dict( ("".join(s), i + 1) - for s, i in zip(sliding_window(2, initials + "J"), range(12)) + for s, i in zip(sliding_window(2, initials + "J"), range(12), strict=False) ) result: list[tuple[int, ...]] = [] for i, season in enumerate(seasons): @@ -602,7 +602,7 @@ class SeasonResampler(Resampler): def __post_init__(self): self.season_inds = season_to_month_tuple(self.seasons) - self.season_tuples = dict(zip(self.seasons, self.season_inds)) + self.season_tuples = dict(zip(self.seasons, self.season_inds, strict=False)) def factorize(self, group): if group.ndim != 1: @@ -624,7 +624,7 @@ def factorize(self, group): season_label = np.full(group.shape, "", dtype=f"U{nstr}") # offset years for seasons with December and January - for season_str, season_ind in zip(seasons, season_inds): + for season_str, season_ind in zip(seasons, season_inds, strict=False): season_label[month.isin(season_ind)] = season_str if "DJ" in season_str: after_dec = season_ind[season_str.index("D") + 1 :] @@ -651,14 +651,16 @@ def factorize(self, group): ) sbins = first_items.values.astype(int) - group_indices = [slice(i, j) for i, j in zip(sbins[:-1], sbins[1:])] + group_indices = [ + slice(i, j) for i, j in zip(sbins[:-1], sbins[1:], strict=False) + ] group_indices += [slice(sbins[-1], None)] # Make sure the first and last timestamps # are for the correct months,if not we have incomplete seasons unique_codes = np.arange(len(unique_coord)) if self.drop_incomplete: - for idx, slicer in zip([0, -1], (slice(1, None), slice(-1))): + for idx, slicer in zip([0, -1], (slice(1, None), slice(-1)), strict=False): stamp_year, stamp_season = frame.index[idx] code = seasons.index(stamp_season) stamp_month = season_inds[code][idx]