Skip to content

Commit 24e83ac

Browse files
Apply new ruff rules (pydata#10428)
Co-authored-by: Kai Mühlbauer <kai.muehlbauer@uni-bonn.de>
1 parent 4d0300e commit 24e83ac

File tree

20 files changed

+62
-58
lines changed

20 files changed

+62
-58
lines changed

xarray/backends/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from functools import partial
1313
from io import BytesIO
14+
from itertools import starmap
1415
from numbers import Number
1516
from typing import (
1617
TYPE_CHECKING,
@@ -2109,10 +2110,9 @@ def save_mfdataset(
21092110
import dask
21102111

21112112
return dask.delayed(
2112-
[
2113-
dask.delayed(_finalize_store)(w, s)
2114-
for w, s in zip(writes, stores, strict=True)
2115-
]
2113+
list(
2114+
starmap(dask.delayed(_finalize_store), zip(writes, stores, strict=True))
2115+
)
21162116
)
21172117

21182118

xarray/coding/cftimeindex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import math
4545
from datetime import timedelta
46-
from typing import TYPE_CHECKING, Any, Optional
46+
from typing import TYPE_CHECKING, Any
4747

4848
import numpy as np
4949
import pandas as pd
@@ -549,7 +549,7 @@ def __rsub__(self, other):
549549
) from err
550550

551551
def to_datetimeindex(
552-
self, unsafe: bool = False, time_unit: Optional[PDDatetimeUnitOptions] = None
552+
self, unsafe: bool = False, time_unit: PDDatetimeUnitOptions | None = None
553553
) -> pd.DatetimeIndex:
554554
"""If possible, convert this index to a pandas.DatetimeIndex.
555555

xarray/computation/apply_ufunc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,10 @@ def apply_dataset_vfunc(
529529
out: Dataset | tuple[Dataset, ...]
530530
if signature.num_outputs > 1:
531531
out = tuple(
532-
_fast_dataset(*args)
533-
for args in zip(result_vars, list_of_coords, list_of_indexes, strict=True)
532+
itertools.starmap(
533+
_fast_dataset,
534+
zip(result_vars, list_of_coords, list_of_indexes, strict=True),
535+
)
534536
)
535537
else:
536538
(coord_vars,) = list_of_coords
@@ -600,9 +602,7 @@ def apply_groupby_func(func, *args):
600602
iterator = itertools.repeat(arg)
601603
iterators.append(iterator)
602604

603-
applied: Iterator = (
604-
func(*zipped_args) for zipped_args in zip(*iterators, strict=False)
605-
)
605+
applied: Iterator = itertools.starmap(func, zip(*iterators, strict=False))
606606
applied_example, applied = peek_at(applied)
607607
combine = first_groupby._combine # type: ignore[attr-defined]
608608
if isinstance(applied_example, tuple):

xarray/computation/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def _cov_corr(
258258
weights: T_DataArray | None = None,
259259
dim: Dims = None,
260260
ddof: int = 0,
261-
method: Literal["cov", "corr", None] = None,
261+
method: Literal["cov", "corr"] | None = None,
262262
) -> T_DataArray:
263263
"""
264264
Internal method for xr.cov() and xr.corr() so only have to

xarray/core/dataset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,9 +2334,10 @@ def info(self, buf: IO | None = None) -> None:
23342334
if buf is None: # pragma: no cover
23352335
buf = sys.stdout
23362336

2337-
lines = []
2338-
lines.append("xarray.Dataset {")
2339-
lines.append("dimensions:")
2337+
lines = [
2338+
"xarray.Dataset {",
2339+
"dimensions:",
2340+
]
23402341
for name, size in self.sizes.items():
23412342
lines.append(f"\t{name} = {size} ;")
23422343
lines.append("\nvariables:")
@@ -9708,7 +9709,7 @@ def convert_calendar(
97089709
self,
97099710
calendar: CFCalendar,
97109711
dim: Hashable = "time",
9711-
align_on: Literal["date", "year", None] = None,
9712+
align_on: Literal["date", "year"] | None = None,
97129713
missing: Any | None = None,
97139714
use_cftime: bool | None = None,
97149715
) -> Self:

xarray/core/indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ def _wrap_index_equals(
19551955
f"the signature ``{index_cls_name}.equals(self, other)`` is deprecated. "
19561956
f"Please update it to "
19571957
f"``{index_cls_name}.equals(self, other, *, exclude=None)`` "
1958-
"or kindly ask the maintainers of ``{index_cls_name}`` to do it. "
1958+
f"or kindly ask the maintainers of ``{index_cls_name}`` to do it. "
19591959
"See documentation of xarray.Index.equals() for more info.",
19601960
FutureWarning,
19611961
)

xarray/core/options.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class T_Options(TypedDict):
4646
display_values_threshold: int
4747
display_style: Literal["text", "html"]
4848
display_width: int
49-
display_expand_attrs: Literal["default", True, False]
50-
display_expand_coords: Literal["default", True, False]
51-
display_expand_data_vars: Literal["default", True, False]
52-
display_expand_data: Literal["default", True, False]
53-
display_expand_groups: Literal["default", True, False]
54-
display_expand_indexes: Literal["default", True, False]
55-
display_default_indexes: Literal["default", True, False]
49+
display_expand_attrs: Literal["default"] | bool
50+
display_expand_coords: Literal["default"] | bool
51+
display_expand_data_vars: Literal["default"] | bool
52+
display_expand_data: Literal["default"] | bool
53+
display_expand_groups: Literal["default"] | bool
54+
display_expand_indexes: Literal["default"] | bool
55+
display_default_indexes: Literal["default"] | bool
5656
enable_cftimeindex: bool
5757
file_cache_maxsize: int
58-
keep_attrs: Literal["default", True, False]
58+
keep_attrs: Literal["default"] | bool
5959
warn_for_unclosed_files: bool
6060
use_bottleneck: bool
6161
use_flox: bool

xarray/core/types.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,16 @@ def copy(
253253
InterpnOptions = Literal["linear", "nearest", "slinear", "cubic", "quintic", "pchip"]
254254
InterpOptions = Union[Interp1dOptions, InterpolantOptions, InterpnOptions]
255255

256-
DatetimeUnitOptions = Literal[
257-
"W", "D", "h", "m", "s", "ms", "us", "μs", "ns", "ps", "fs", "as", None
258-
]
256+
DatetimeUnitOptions = (
257+
Literal["W", "D", "h", "m", "s", "ms", "us", "μs", "ns", "ps", "fs", "as"] | None
258+
)
259259
NPDatetimeUnitOptions = Literal["D", "h", "m", "s", "ms", "us", "ns"]
260260
PDDatetimeUnitOptions = Literal["s", "ms", "us", "ns"]
261261

262-
QueryEngineOptions = Literal["python", "numexpr", None]
262+
QueryEngineOptions = Literal["python", "numexpr"] | None
263263
QueryParserOptions = Literal["pandas", "python"]
264264

265-
ReindexMethodOptions = Literal["nearest", "pad", "ffill", "backfill", "bfill", None]
265+
ReindexMethodOptions = Literal["nearest", "pad", "ffill", "backfill", "bfill"] | None
266266

267267
PadModeOptions = Literal[
268268
"constant",
@@ -281,7 +281,7 @@ def copy(
281281
T_DatasetPadConstantValues = (
282282
T_VarPadConstantValues | Mapping[Any, T_VarPadConstantValues]
283283
)
284-
PadReflectOptions = Literal["even", "odd", None]
284+
PadReflectOptions = Literal["even", "odd"] | None
285285

286286
CFCalendar = Literal[
287287
"standard",
@@ -299,10 +299,10 @@ def copy(
299299
SideOptions = Literal["left", "right"]
300300
InclusiveOptions = Literal["both", "neither", "left", "right"]
301301

302-
ScaleOptions = Literal["linear", "symlog", "log", "logit", None]
303-
HueStyleOptions = Literal["continuous", "discrete", None]
302+
ScaleOptions = Literal["linear", "symlog", "log", "logit"] | None
303+
HueStyleOptions = Literal["continuous", "discrete"] | None
304304
AspectOptions = Union[Literal["auto", "equal"], float, None]
305-
ExtendOptions = Literal["neither", "both", "min", "max", None]
305+
ExtendOptions = Literal["neither", "both", "min", "max"] | None
306306

307307

308308
_T_co = TypeVar("_T_co", covariant=True)

xarray/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def equivalent(first: T, second: T) -> bool:
241241
def list_equiv(first: Sequence[T], second: Sequence[T]) -> bool:
242242
if len(first) != len(second):
243243
return False
244-
return all(equivalent(f, s) for f, s in zip(first, second, strict=True))
244+
return all(itertools.starmap(equivalent, zip(first, second, strict=True)))
245245

246246

247247
def peek_at(iterable: Iterable[T]) -> tuple[T, Iterator[T]]:

xarray/core/variable.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,8 +2232,7 @@ def coarsen_reshape(self, windows, boundary, side):
22322232
for i, d in enumerate(variable.dims):
22332233
if d in windows:
22342234
size = variable.shape[i]
2235-
shape.append(int(size / windows[d]))
2236-
shape.append(windows[d])
2235+
shape.extend((int(size / windows[d]), windows[d]))
22372236
axis_count += 1
22382237
axes.append(i + axis_count)
22392238
else:

0 commit comments

Comments
 (0)