Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 20, 2024
1 parent 13d6bdf commit 54b2ef1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion xarray/core/toolzcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
14 changes: 8 additions & 6 deletions xarray/groupers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
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,
GroupIndices,
ResampleCompatible,
SideOptions,
)
from xarray.core.toolzcompat import sliding_window
from xarray.core.variable import Variable

__all__ = [
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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 :]
Expand All @@ -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]
Expand Down

0 comments on commit 54b2ef1

Please sign in to comment.