Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ repos:
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.11
rev: v0.13.3
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/keewis/blackdoc
rev: v0.4.1
hooks:
- id: blackdoc
exclude: "generate_aggregations.py"
additional_dependencies: ["black==24.8.0"]
# Disabled: blackdoc v0.4.3 has compatibility issues with Python 3.13
# Re-enable when blackdoc is updated to support Python 3.13
# - repo: https://github.com/keewis/blackdoc
# rev: v0.4.3
# hooks:
# - id: blackdoc
# exclude: "generate_aggregations.py"
# additional_dependencies: ["black==24.8.0"]
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.6.2
hooks:
- id: prettier
args: [--cache-location=.prettier_cache/cache]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
rev: v1.18.2
hooks:
- id: mypy
# Copied from setup.cfg
Expand Down Expand Up @@ -73,6 +75,6 @@ repos:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]
- repo: https://github.com/adhtruong/mirrors-typos
rev: v1.35.6
rev: v1.37.2
hooks:
- id: typos
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ aso = "aso"
# Technical terms
nd = "nd"
nin = "nin"
nclusive = "nclusive" # part of "inclusive" in error messages

# Variable names
ba = "ba"
Expand Down
6 changes: 3 additions & 3 deletions xarray/computation/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def _calc_idxminmax(
array = array.where(~allna, 0)

# This will run argmin or argmax.
indx = func(array, dim=dim, axis=None, keep_attrs=keep_attrs, skipna=skipna)
index = func(array, dim=dim, axis=None, keep_attrs=keep_attrs, skipna=skipna)

# Handle chunked arrays (e.g. dask).
coord = array[dim]._variable.to_base_variable()
Expand All @@ -943,13 +943,13 @@ def _calc_idxminmax(
else:
coord = coord.copy(data=to_like_array(array[dim].data, array.data))

res = indx._replace(coord[(indx.variable,)]).rename(dim)
res = index._replace(coord[(index.variable,)]).rename(dim)

if skipna or (skipna is None and array.dtype.kind in na_dtypes):
# Put the NaN values back in after removing them
res = res.where(~allna, fill_value)

# Copy attributes from argmin/argmax, if any
res.attrs = indx.attrs
res.attrs = index.attrs

return res
2 changes: 1 addition & 1 deletion xarray/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def shuffle_to_chunks(self, chunks: T_Chunks = None):
dask.dataframe.DataFrame.shuffle
dask.array.shuffle
"""
(grouper,) = self.groupers
(_grouper,) = self.groupers
return self._shuffle_obj(chunks).drop_vars(RESAMPLE_DIM)

def _first_or_last(
Expand Down
8 changes: 4 additions & 4 deletions xarray/core/treenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def descendants(self) -> tuple[Self, ...]:
DataTree.subtree
"""
all_nodes = tuple(self.subtree)
this_node, *descendants = all_nodes
_this_node, *descendants = all_nodes
return tuple(descendants)

@property
Expand Down Expand Up @@ -546,7 +546,7 @@ def _get_item(self, path: str | NodePath) -> Self | DataArray:

if path.root:
current_node = self.root
root, *parts = list(path.parts)
_root, *parts = list(path.parts)
else:
current_node = self
parts = list(path.parts)
Expand Down Expand Up @@ -614,7 +614,7 @@ def _set_item(
if path.root:
# absolute path
current_node = self.root
root, *parts, name = path.parts
_root, *parts, name = path.parts
else:
# relative path
current_node = self
Expand Down Expand Up @@ -738,7 +738,7 @@ def path(self) -> str:
if self.is_root:
return "/"
else:
root, *ancestors = tuple(reversed(self.parents))
_root, *ancestors = tuple(reversed(self.parents))
# don't include name of root because (a) root might not have a name & (b) we want path relative to root.
names = [*(node.name for node in ancestors), self.name]
return "/" + "/".join(names) # type: ignore[arg-type]
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def convert_non_numpy_type(data):
if isinstance(data, np.ma.MaskedArray):
mask = np.ma.getmaskarray(data)
if mask.any():
dtype, fill_value = dtypes.maybe_promote(data.dtype)
_dtype, fill_value = dtypes.maybe_promote(data.dtype)
data = duck_array_ops.where_method(data, ~mask, fill_value)
else:
data = np.asarray(data)
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ def _parse_size(
else:
levels = numbers = np.sort(np.unique(flatdata))

min_width, default_width, max_width = _MARKERSIZE_RANGE
min_width, _default_width, max_width = _MARKERSIZE_RANGE
# width_range = min_width, max_width

if norm is None:
Expand Down
2 changes: 1 addition & 1 deletion xarray/structure/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _combine_1d(


def _new_tile_id(single_id_ds_pair):
tile_id, ds = single_id_ds_pair
tile_id, _ds = single_id_ds_pair
return tile_id[1:]


Expand Down
54 changes: 27 additions & 27 deletions xarray/tests/test_accessor_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_contains(dtype) -> None:
pat_re = re.compile("(/w+)")
with pytest.raises(
ValueError,
match="Must use regular expression matching for regular expression object.",
match=r"Must use regular expression matching for regular expression object.",
):
values.str.contains(pat_re, regex=False)

Expand Down Expand Up @@ -482,17 +482,17 @@ def test_replace_compiled_regex(dtype) -> None:
pat3 = re.compile(dtype("BAD[_]*"))

with pytest.raises(
ValueError, match="Flags cannot be set when pat is a compiled regex."
ValueError, match=r"Flags cannot be set when pat is a compiled regex."
):
result = values.str.replace(pat3, "", flags=re.IGNORECASE)

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
result = values.str.replace(pat3, "", case=False)

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
result = values.str.replace(pat3, "", case=True)

Expand Down Expand Up @@ -555,22 +555,22 @@ def test_extract_extractall_findall_empty_raises(dtype) -> None:

value = xr.DataArray([["a"]], dims=["X", "Y"]).astype(dtype)

with pytest.raises(ValueError, match="No capture groups found in pattern."):
with pytest.raises(ValueError, match=r"No capture groups found in pattern."):
value.str.extract(pat=pat_str, dim="ZZ")

with pytest.raises(ValueError, match="No capture groups found in pattern."):
with pytest.raises(ValueError, match=r"No capture groups found in pattern."):
value.str.extract(pat=pat_re, dim="ZZ")

with pytest.raises(ValueError, match="No capture groups found in pattern."):
with pytest.raises(ValueError, match=r"No capture groups found in pattern."):
value.str.extractall(pat=pat_str, group_dim="XX", match_dim="YY")

with pytest.raises(ValueError, match="No capture groups found in pattern."):
with pytest.raises(ValueError, match=r"No capture groups found in pattern."):
value.str.extractall(pat=pat_re, group_dim="XX", match_dim="YY")

with pytest.raises(ValueError, match="No capture groups found in pattern."):
with pytest.raises(ValueError, match=r"No capture groups found in pattern."):
value.str.findall(pat=pat_str)

with pytest.raises(ValueError, match="No capture groups found in pattern."):
with pytest.raises(ValueError, match=r"No capture groups found in pattern."):
value.str.findall(pat=pat_re)


Expand All @@ -582,13 +582,13 @@ def test_extract_multi_None_raises(dtype) -> None:

with pytest.raises(
ValueError,
match="Dimension must be specified if more than one capture group is given.",
match=r"Dimension must be specified if more than one capture group is given.",
):
value.str.extract(pat=pat_str, dim=None)

with pytest.raises(
ValueError,
match="Dimension must be specified if more than one capture group is given.",
match=r"Dimension must be specified if more than one capture group is given.",
):
value.str.extract(pat=pat_re, dim=None)

Expand All @@ -600,32 +600,32 @@ def test_extract_extractall_findall_case_re_raises(dtype) -> None:
value = xr.DataArray([["a"]], dims=["X", "Y"]).astype(dtype)

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
value.str.extract(pat=pat_re, case=True, dim="ZZ")

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
value.str.extract(pat=pat_re, case=False, dim="ZZ")

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
value.str.extractall(pat=pat_re, case=True, group_dim="XX", match_dim="YY")

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
value.str.extractall(pat=pat_re, case=False, group_dim="XX", match_dim="YY")

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
value.str.findall(pat=pat_re, case=True)

with pytest.raises(
ValueError, match="Case cannot be set when pat is a compiled regex."
ValueError, match=r"Case cannot be set when pat is a compiled regex."
):
value.str.findall(pat=pat_re, case=False)

Expand All @@ -636,39 +636,39 @@ def test_extract_extractall_name_collision_raises(dtype) -> None:

value = xr.DataArray([["a"]], dims=["X", "Y"]).astype(dtype)

with pytest.raises(KeyError, match="Dimension 'X' already present in DataArray."):
with pytest.raises(KeyError, match=r"Dimension 'X' already present in DataArray."):
value.str.extract(pat=pat_str, dim="X")

with pytest.raises(KeyError, match="Dimension 'X' already present in DataArray."):
with pytest.raises(KeyError, match=r"Dimension 'X' already present in DataArray."):
value.str.extract(pat=pat_re, dim="X")

with pytest.raises(
KeyError, match="Group dimension 'X' already present in DataArray."
KeyError, match=r"Group dimension 'X' already present in DataArray."
):
value.str.extractall(pat=pat_str, group_dim="X", match_dim="ZZ")

with pytest.raises(
KeyError, match="Group dimension 'X' already present in DataArray."
KeyError, match=r"Group dimension 'X' already present in DataArray."
):
value.str.extractall(pat=pat_re, group_dim="X", match_dim="YY")

with pytest.raises(
KeyError, match="Match dimension 'Y' already present in DataArray."
KeyError, match=r"Match dimension 'Y' already present in DataArray."
):
value.str.extractall(pat=pat_str, group_dim="XX", match_dim="Y")

with pytest.raises(
KeyError, match="Match dimension 'Y' already present in DataArray."
KeyError, match=r"Match dimension 'Y' already present in DataArray."
):
value.str.extractall(pat=pat_re, group_dim="XX", match_dim="Y")

with pytest.raises(
KeyError, match="Group dimension 'ZZ' is the same as match dimension 'ZZ'."
KeyError, match=r"Group dimension 'ZZ' is the same as match dimension 'ZZ'."
):
value.str.extractall(pat=pat_str, group_dim="ZZ", match_dim="ZZ")

with pytest.raises(
KeyError, match="Group dimension 'ZZ' is the same as match dimension 'ZZ'."
KeyError, match=r"Group dimension 'ZZ' is the same as match dimension 'ZZ'."
):
value.str.extractall(pat=pat_re, group_dim="ZZ", match_dim="ZZ")

Expand Down Expand Up @@ -3526,7 +3526,7 @@ def test_join_2d(dtype) -> None:
assert_identical(res_space_y, targ_space_y)

with pytest.raises(
ValueError, match="Dimension must be specified for multidimensional arrays."
ValueError, match=r"Dimension must be specified for multidimensional arrays."
):
values.str.join()

Expand Down
Loading
Loading