Skip to content

Commit a9e12d3

Browse files
max-sixtypre-commit-ci[bot]
authored andcommitted
Fix for ruff 0.4.3 (#9007)
* Fix for ruff 0.4.3 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 59ec695 commit a9e12d3

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

ci/min_deps_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def process_pkg(
133133
- publication date of version suggested by policy (YYYY-MM-DD)
134134
- status ("<", "=", "> (!)")
135135
"""
136-
print("Analyzing %s..." % pkg)
136+
print(f"Analyzing {pkg}...")
137137
versions = query_conda(pkg)
138138

139139
try:

xarray/datatree_/datatree/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# import public API
22
from xarray.core.treenode import InvalidTreeError, NotFoundInTreeError
33

4-
54
__all__ = (
65
"InvalidTreeError",
76
"NotFoundInTreeError",

xarray/datatree_/datatree/common.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"""
77

88
import warnings
9+
from collections.abc import Hashable, Iterable, Mapping
910
from contextlib import suppress
10-
from typing import Any, Hashable, Iterable, List, Mapping
11+
from typing import Any
1112

1213

1314
class TreeAttrAccessMixin:
@@ -83,16 +84,14 @@ def __setattr__(self, name: str, value: Any) -> None:
8384
except AttributeError as e:
8485
# Don't accidentally shadow custom AttributeErrors, e.g.
8586
# DataArray.dims.setter
86-
if str(e) != "{!r} object has no attribute {!r}".format(
87-
type(self).__name__, name
88-
):
87+
if str(e) != f"{type(self).__name__!r} object has no attribute {name!r}":
8988
raise
9089
raise AttributeError(
9190
f"cannot set attribute {name!r} on a {type(self).__name__!r} object. Use __setitem__ style"
9291
"assignment (e.g., `ds['name'] = ...`) instead of assigning variables."
9392
) from e
9493

95-
def __dir__(self) -> List[str]:
94+
def __dir__(self) -> list[str]:
9695
"""Provide method name lookup and completion. Only provide 'public'
9796
methods.
9897
"""

xarray/tests/test_dataset.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_repr(self) -> None:
284284
Dimensions: (dim2: 9, dim3: 10, time: 20, dim1: 8)
285285
Coordinates:
286286
* dim2 (dim2) float64 72B 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
287-
* dim3 (dim3) %s 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
287+
* dim3 (dim3) {} 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
288288
* time (time) datetime64[ns] 160B 2000-01-01 2000-01-02 ... 2000-01-20
289289
numbers (dim3) int64 80B 0 1 2 0 0 1 1 2 2 3
290290
Dimensions without coordinates: dim1
@@ -293,8 +293,9 @@ def test_repr(self) -> None:
293293
var2 (dim1, dim2) float64 576B 1.162 -1.097 -2.123 ... 1.267 0.3328
294294
var3 (dim3, dim1) float64 640B 0.5565 -0.2121 0.4563 ... -0.2452 -0.3616
295295
Attributes:
296-
foo: bar"""
297-
% data["dim3"].dtype
296+
foo: bar""".format(
297+
data["dim3"].dtype
298+
)
298299
)
299300
actual = "\n".join(x.rstrip() for x in repr(data).split("\n"))
300301
print(actual)

xarray/tests/test_groupby.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ def test_da_groupby_assign_coords() -> None:
577577
def test_groupby_repr(obj, dim) -> None:
578578
actual = repr(obj.groupby(dim))
579579
expected = f"{obj.__class__.__name__}GroupBy"
580-
expected += ", grouped over %r" % dim
581-
expected += "\n%r groups with labels " % (len(np.unique(obj[dim])))
580+
expected += f", grouped over {dim!r}"
581+
expected += f"\n{len(np.unique(obj[dim]))!r} groups with labels "
582582
if dim == "x":
583583
expected += "1, 2, 3, 4, 5."
584584
elif dim == "y":
@@ -595,7 +595,7 @@ def test_groupby_repr_datetime(obj) -> None:
595595
actual = repr(obj.groupby("t.month"))
596596
expected = f"{obj.__class__.__name__}GroupBy"
597597
expected += ", grouped over 'month'"
598-
expected += "\n%r groups with labels " % (len(np.unique(obj.t.dt.month)))
598+
expected += f"\n{len(np.unique(obj.t.dt.month))!r} groups with labels "
599599
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12."
600600
assert actual == expected
601601

xarray/tests/test_rolling.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_rolling_reduce(
254254
rolling_obj = da.rolling(time=window, center=center, min_periods=min_periods)
255255

256256
# add nan prefix to numpy methods to get similar # behavior as bottleneck
257-
actual = rolling_obj.reduce(getattr(np, "nan%s" % name))
257+
actual = rolling_obj.reduce(getattr(np, f"nan{name}"))
258258
expected = getattr(rolling_obj, name)()
259259
assert_allclose(actual, expected)
260260
assert actual.sizes == expected.sizes
@@ -276,7 +276,7 @@ def test_rolling_reduce_nonnumeric(
276276
rolling_obj = da.rolling(time=window, center=center, min_periods=min_periods)
277277

278278
# add nan prefix to numpy methods to get similar behavior as bottleneck
279-
actual = rolling_obj.reduce(getattr(np, "nan%s" % name))
279+
actual = rolling_obj.reduce(getattr(np, f"nan{name}"))
280280
expected = getattr(rolling_obj, name)()
281281
assert_allclose(actual, expected)
282282
assert actual.sizes == expected.sizes
@@ -741,7 +741,7 @@ def test_rolling_reduce(self, ds, center, min_periods, window, name) -> None:
741741
rolling_obj = ds.rolling(time=window, center=center, min_periods=min_periods)
742742

743743
# add nan prefix to numpy methods to get similar behavior as bottleneck
744-
actual = rolling_obj.reduce(getattr(np, "nan%s" % name))
744+
actual = rolling_obj.reduce(getattr(np, f"nan{name}"))
745745
expected = getattr(rolling_obj, name)()
746746
assert_allclose(actual, expected)
747747
assert ds.sizes == actual.sizes

0 commit comments

Comments
 (0)