Skip to content

Commit

Permalink
Apply ruff rule RUF007 (#9739)
Browse files Browse the repository at this point in the history
RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs
  • Loading branch information
DimitriPapadopoulos authored Nov 7, 2024
1 parent 8aab23e commit 88169c7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ ignore = [
"RUF002",
"RUF003",
"RUF005",
"RUF007",
"RUF012",
]
extend-select = [
Expand Down
4 changes: 2 additions & 2 deletions xarray/groupers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datetime
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from itertools import pairwise
from typing import TYPE_CHECKING, Any, Literal, cast

import numpy as np
Expand Down Expand Up @@ -496,8 +497,7 @@ def factorize(self, group: T_Group) -> EncodedGroups:
full_index, first_items, codes_ = self._get_index_and_items()
sbins = first_items.values.astype(np.int64)
group_indices: GroupIndices = tuple(
[slice(i, j) for i, j in zip(sbins[:-1], sbins[1:], strict=True)]
+ [slice(sbins[-1], None)]
[slice(i, j) for i, j in pairwise(sbins)] + [slice(sbins[-1], None)]
)

unique_coord = Variable(
Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import operator
import warnings
from itertools import pairwise
from unittest import mock

import numpy as np
Expand Down Expand Up @@ -1732,7 +1733,7 @@ def test_groupby_bins_multidim(self) -> None:
bincoord = np.array(
[
pd.Interval(left, right, closed="right")
for left, right in zip(bins[:-1], bins[1:], strict=True)
for left, right in pairwise(bins)
],
dtype=object,
)
Expand Down

0 comments on commit 88169c7

Please sign in to comment.