Skip to content

Commit c1126de

Browse files
pre-commit-ci[bot]headtr1ckjsignell
authored
Update pre-commit hooks (#11211)
* Update pre-commit hooks updates: - [github.com/astral-sh/ruff-pre-commit: v0.14.14 → v0.15.4](astral-sh/ruff-pre-commit@v0.14.14...v0.15.4) - [github.com/abravalheri/validate-pyproject: v0.24.1 → v0.25](abravalheri/validate-pyproject@v0.24.1...v0.25) - [github.com/adhtruong/mirrors-typos: v1.42.3 → v1.44.0](adhtruong/mirrors-typos@v1.42.3...v1.44.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * apply ruff changes * fix mypy stuff * fix stubtest, don't ask me why or how --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Michael Niklas <mick.niklas@gmail.com> Co-authored-by: Julia Signell <jsignell@gmail.com>
1 parent b89bf89 commit c1126de

File tree

12 files changed

+40
-41
lines changed

12 files changed

+40
-41
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
- id: rst-inline-touching-normal
2525
- id: text-unicode-replacement-char
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: v0.14.14
27+
rev: v0.15.4
2828
hooks:
2929
- id: ruff-check
3030
args: ["--fix", "--show-fixes"]
@@ -71,11 +71,11 @@ repos:
7171
- id: taplo-lint
7272
args: ["--no-schema"]
7373
- repo: https://github.com/abravalheri/validate-pyproject
74-
rev: v0.24.1
74+
rev: v0.25
7575
hooks:
7676
- id: validate-pyproject
7777
additional_dependencies: ["validate-pyproject-schema-store[all]"]
7878
- repo: https://github.com/adhtruong/mirrors-typos
79-
rev: v1.42.3
79+
rev: v1.44.0
8080
hooks:
8181
- id: typos

xarray/backends/zarr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ class FillValueCoder:
123123

124124
@classmethod
125125
def encode(cls, value: int | float | str | bytes, dtype: np.dtype[Any]) -> Any:
126-
if dtype.kind in "S":
126+
if dtype.kind == "S":
127127
# byte string, this implies that 'value' must also be `bytes` dtype.
128128
assert isinstance(value, bytes)
129129
return base64.standard_b64encode(value).decode()
130-
elif dtype.kind in "b":
130+
elif dtype.kind == "b":
131131
# boolean
132132
return bool(value)
133133
elif dtype.kind in "iu":
134134
# todo: do we want to check for decimals?
135135
return int(value)
136-
elif dtype.kind in "f":
136+
elif dtype.kind == "f":
137137
return base64.standard_b64encode(struct.pack("<d", float(value))).decode()
138-
elif dtype.kind in "U":
138+
elif dtype.kind == "U":
139139
return str(value)
140140
else:
141141
raise ValueError(f"Failed to encode fill_value. Unsupported dtype {dtype}")
@@ -150,10 +150,10 @@ def decode(cls, value: int | float | str | bytes, dtype: str | np.dtype[Any]):
150150
assert isinstance(value, str | bytes)
151151
return base64.standard_b64decode(value)
152152
np_dtype = np.dtype(dtype)
153-
if np_dtype.kind in "f":
153+
if np_dtype.kind == "f":
154154
assert isinstance(value, str | bytes)
155155
return struct.unpack("<d", base64.standard_b64decode(value))[0]
156-
elif np_dtype.kind in "b":
156+
elif np_dtype.kind == "b":
157157
return bool(value)
158158
elif np_dtype.kind in "iu":
159159
return int(value)
@@ -1650,7 +1650,7 @@ def guess_can_open(self, filename_or_obj: T_PathFileOrDataStore) -> bool:
16501650
# allow a trailing slash to account for an autocomplete
16511651
# adding it.
16521652
_, ext = os.path.splitext(str(filename_or_obj).rstrip("/"))
1653-
return ext in [".zarr"]
1653+
return ext == ".zarr"
16541654

16551655
return False
16561656

xarray/coding/times.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def _check_date_for_units_since_refdate(
397397
delta = date * np.timedelta64(1, unit)
398398
if not np.isnan(delta):
399399
# this will raise on dtype overflow for integer dtypes
400-
if date.dtype.kind in "u" and not np.int64(delta) == date:
400+
if date.dtype.kind == "u" and not np.int64(delta) == date:
401401
raise OutOfBoundsTimedelta(
402402
"DType overflow in Datetime/Timedelta calculation."
403403
)
@@ -421,7 +421,7 @@ def _check_timedelta_range(value, data_unit, time_unit):
421421
delta = value * np.timedelta64(1, data_unit)
422422
if not np.isnan(delta):
423423
# this will raise on dtype overflow for integer dtypes
424-
if value.dtype.kind in "u" and not np.int64(delta) == value:
424+
if value.dtype.kind == "u" and not np.int64(delta) == value:
425425
raise OutOfBoundsTimedelta(
426426
"DType overflow in Datetime/Timedelta calculation."
427427
)
@@ -521,7 +521,7 @@ def _decode_datetime_with_pandas(
521521
# timedelta64 value, and therefore would raise an error in the lines above.
522522
if flat_num_dates.dtype.kind in "iu":
523523
flat_num_dates = flat_num_dates.astype(np.int64)
524-
elif flat_num_dates.dtype.kind in "f":
524+
elif flat_num_dates.dtype.kind == "f":
525525
flat_num_dates = flat_num_dates.astype(np.float64)
526526

527527
timedeltas = _numbers_to_timedelta(

xarray/core/dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7299,6 +7299,7 @@ def _set_sparse_data_from_dataframe(
72997299
) -> None:
73007300
from sparse import COO
73017301

7302+
coords: np.ndarray[tuple[int, int], np.dtype[np.signedinteger]]
73027303
if isinstance(idx, pd.MultiIndex):
73037304
coords = np.stack([np.asarray(code) for code in idx.codes], axis=0)
73047305
is_sorted = idx.is_monotonic_increasing

xarray/core/datatree.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,8 +1695,9 @@ def prune(self, drop_size_zero_vars: bool = False) -> DataTree:
16951695
"""
16961696
non_empty_cond: Callable[[DataTree], bool]
16971697
if drop_size_zero_vars:
1698-
non_empty_cond = lambda node: len(node.data_vars) > 0 and any(
1699-
var.size > 0 for var in node.data_vars.values()
1698+
non_empty_cond = lambda node: (
1699+
len(node.data_vars) > 0
1700+
and any(var.size > 0 for var in node.data_vars.values())
17001701
)
17011702
else:
17021703
non_empty_cond = lambda node: len(node.data_vars) > 0

xarray/core/formatting_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def _build_datatree_displays(tree: DataTree) -> dict[str, _DataTreeDisplay]:
500500
for node in tree.subtree: # breadth-first
501501
parent = node.parent
502502
if parent is not None:
503-
parent_display = displays.get(parent.path, None)
503+
parent_display = displays.get(parent.path)
504504
if parent_display is not None and parent_display.disabled:
505505
break # no need to build display
506506

xarray/core/variable.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import numpy as np
1414
import pandas as pd
15-
from numpy.typing import ArrayLike
1615
from packaging.version import Version
1716

1817
import xarray as xr # only for Dataset and DataArray
@@ -244,7 +243,7 @@ def _possibly_convert_objects(values):
244243

245244

246245
def as_compatible_data(
247-
data: T_DuckArray | ArrayLike, fastpath: bool = False
246+
data: T_DuckArray | np.typing.ArrayLike, fastpath: bool = False
248247
) -> T_DuckArray:
249248
"""Prepare and wrap data to put in a Variable.
250249
@@ -371,7 +370,7 @@ class Variable(NamedArray, AbstractArray, VariableArithmetic):
371370
def __init__(
372371
self,
373372
dims,
374-
data: T_DuckArray | ArrayLike,
373+
data: T_DuckArray | np.typing.ArrayLike,
375374
attrs=None,
376375
encoding=None,
377376
fastpath=False,
@@ -466,7 +465,7 @@ def data(self):
466465
return duck_array
467466

468467
@data.setter # type: ignore[override,unused-ignore]
469-
def data(self, data: T_DuckArray | ArrayLike) -> None:
468+
def data(self, data: T_DuckArray | np.typing.ArrayLike) -> None:
470469
data = as_compatible_data(data)
471470
self._check_shape(data)
472471
self._data = data
@@ -931,7 +930,7 @@ def drop_encoding(self) -> Self:
931930
def _copy(
932931
self,
933932
deep: bool = True,
934-
data: T_DuckArray | ArrayLike | None = None,
933+
data: T_DuckArray | np.typing.ArrayLike | None = None,
935934
memo: dict[int, Any] | None = None,
936935
) -> Self:
937936
if data is None:
@@ -1914,7 +1913,7 @@ def no_conflicts(self, other, equiv=duck_array_ops.array_notnull_equiv):
19141913

19151914
def quantile(
19161915
self,
1917-
q: ArrayLike,
1916+
q: np.typing.ArrayLike,
19181917
dim: str | Sequence[Hashable] | None = None,
19191918
method: QuantileMethods = "linear",
19201919
keep_attrs: bool | None = None,
@@ -2872,7 +2871,9 @@ def concat(
28722871

28732872
return cls(first_var.dims, data, attrs)
28742873

2875-
def copy(self, deep: bool = True, data: T_DuckArray | ArrayLike | None = None):
2874+
def copy(
2875+
self, deep: bool = True, data: T_DuckArray | np.typing.ArrayLike | None = None
2876+
):
28762877
"""Returns a copy of this object.
28772878
28782879
`deep` is ignored since data is stored in the form of

xarray/namedarray/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def from_array(
194194

195195
# TODO: dask.array.ma.MaskedArray also exists, better way?
196196
if isinstance(data, np.ma.MaskedArray):
197-
mask = np.ma.getmaskarray(data) # type: ignore[no-untyped-call]
197+
mask = np.ma.getmaskarray(data)
198198
if mask.any():
199199
# TODO: requires refactoring/vendoring xarray.core.dtypes and
200200
# xarray.core.duck_array_ops

xarray/tests/test_backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,8 +2067,8 @@ def test_mask_and_scale(self) -> None:
20672067

20682068
# now check xarray
20692069
with open_dataset(tmp_file) as ds:
2070-
expected = create_masked_and_scaled_data(np.dtype(dtype))
2071-
assert_identical(expected, ds)
2070+
expected_ds = create_masked_and_scaled_data(np.dtype(dtype))
2071+
assert_identical(expected_ds, ds)
20722072

20732073
def test_0dimensional_variable(self) -> None:
20742074
# This fix verifies our work-around to this netCDF4-python bug:

xarray/tests/test_datatree_mapping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_single_tree_arg(self, create_test_datatree):
4444

4545
def test_single_tree_arg_plus_arg(self, create_test_datatree):
4646
dt = create_test_datatree()
47-
expected = create_test_datatree(modify=lambda ds: (10.0 * ds))
47+
expected = create_test_datatree(modify=lambda ds: 10.0 * ds)
4848
result_tree = map_over_datasets(lambda x, y: x * y, dt, 10.0)
4949
assert_equal(result_tree, expected)
5050

@@ -53,7 +53,7 @@ def test_single_tree_arg_plus_arg(self, create_test_datatree):
5353

5454
def test_single_tree_arg_plus_kwarg(self, create_test_datatree):
5555
dt = create_test_datatree()
56-
expected = create_test_datatree(modify=lambda ds: (10.0 * ds))
56+
expected = create_test_datatree(modify=lambda ds: 10.0 * ds)
5757

5858
def multiply_by_kwarg(ds, **kwargs):
5959
ds = ds * kwargs.pop("multiplier")

0 commit comments

Comments
 (0)