Skip to content

Commit

Permalink
Fix for ruff 0.4.3 (#9007)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
max-sixty and pre-commit-ci[bot] authored May 6, 2024
1 parent e0f2cee commit c01de39
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ci/min_deps_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def process_pkg(
- publication date of version suggested by policy (YYYY-MM-DD)
- status ("<", "=", "> (!)")
"""
print("Analyzing %s..." % pkg)
print(f"Analyzing {pkg}...")
versions = query_conda(pkg)

try:
Expand Down
1 change: 0 additions & 1 deletion xarray/datatree_/datatree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# import public API
from xarray.core.treenode import InvalidTreeError, NotFoundInTreeError


__all__ = (
"InvalidTreeError",
"NotFoundInTreeError",
Expand Down
9 changes: 4 additions & 5 deletions xarray/datatree_/datatree/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"""

import warnings
from collections.abc import Hashable, Iterable, Mapping
from contextlib import suppress
from typing import Any, Hashable, Iterable, List, Mapping
from typing import Any


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

def __dir__(self) -> List[str]:
def __dir__(self) -> list[str]:
"""Provide method name lookup and completion. Only provide 'public'
methods.
"""
Expand Down
7 changes: 4 additions & 3 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_repr(self) -> None:
Dimensions: (dim2: 9, dim3: 10, time: 20, dim1: 8)
Coordinates:
* dim2 (dim2) float64 72B 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
* dim3 (dim3) %s 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
* dim3 (dim3) {} 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
* time (time) datetime64[ns] 160B 2000-01-01 2000-01-02 ... 2000-01-20
numbers (dim3) int64 80B 0 1 2 0 0 1 1 2 2 3
Dimensions without coordinates: dim1
Expand All @@ -293,8 +293,9 @@ def test_repr(self) -> None:
var2 (dim1, dim2) float64 576B 1.162 -1.097 -2.123 ... 1.267 0.3328
var3 (dim3, dim1) float64 640B 0.5565 -0.2121 0.4563 ... -0.2452 -0.3616
Attributes:
foo: bar"""
% data["dim3"].dtype
foo: bar""".format(
data["dim3"].dtype
)
)
actual = "\n".join(x.rstrip() for x in repr(data).split("\n"))
print(actual)
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ def test_da_groupby_assign_coords() -> None:
def test_groupby_repr(obj, dim) -> None:
actual = repr(obj.groupby(dim))
expected = f"{obj.__class__.__name__}GroupBy"
expected += ", grouped over %r" % dim
expected += "\n%r groups with labels " % (len(np.unique(obj[dim])))
expected += f", grouped over {dim!r}"
expected += f"\n{len(np.unique(obj[dim]))!r} groups with labels "
if dim == "x":
expected += "1, 2, 3, 4, 5."
elif dim == "y":
Expand All @@ -595,7 +595,7 @@ def test_groupby_repr_datetime(obj) -> None:
actual = repr(obj.groupby("t.month"))
expected = f"{obj.__class__.__name__}GroupBy"
expected += ", grouped over 'month'"
expected += "\n%r groups with labels " % (len(np.unique(obj.t.dt.month)))
expected += f"\n{len(np.unique(obj.t.dt.month))!r} groups with labels "
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12."
assert actual == expected

Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_rolling_reduce(
rolling_obj = da.rolling(time=window, center=center, min_periods=min_periods)

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

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

# add nan prefix to numpy methods to get similar behavior as bottleneck
actual = rolling_obj.reduce(getattr(np, "nan%s" % name))
actual = rolling_obj.reduce(getattr(np, f"nan{name}"))
expected = getattr(rolling_obj, name)()
assert_allclose(actual, expected)
assert ds.sizes == actual.sizes
Expand Down

0 comments on commit c01de39

Please sign in to comment.