Skip to content

Commit

Permalink
Apply ruff/pyupgrade rule UP031
Browse files Browse the repository at this point in the history
UP031 Use format specifiers instead of percent format
  • Loading branch information
DimitriPapadopoulos committed Nov 24, 2024
1 parent 0bddbd6 commit 20fe30d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/dataset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def make_ds(self, nfiles=10):
ds.attrs = {"history": "created for xarray benchmarking"}

self.ds_list.append(ds)
self.filenames_list.append("test_netcdf_%i.nc" % i)
self.filenames_list.append(f"test_netcdf_{i}.nc")


class IOWriteMultipleNetCDF3(IOMultipleNetCDF):
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7615,7 +7615,7 @@ def from_dataframe(cls, dataframe: pd.DataFrame, sparse: bool = False) -> Self:

if isinstance(idx, pd.MultiIndex):
dims = tuple(
name if name is not None else "level_%i" % n # type: ignore[redundant-expr]
name if name is not None else f"level_{n}" # type: ignore[redundant-expr]
for n, name in enumerate(idx.names)
)
for dim, lev in zip(dims, idx.levels, strict=True):
Expand Down
4 changes: 2 additions & 2 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,11 @@ def _infer_interval_breaks(coord, axis=0, scale=None, check_monotonic=False):
if check_monotonic and not _is_monotonic(coord, axis=axis):
raise ValueError(
"The input coordinate is not sorted in increasing "
"order along axis %d. This can lead to unexpected "
f"order along axis {axis}. This can lead to unexpected "
"results. Consider calling the `sortby` method on "
"the input DataArray. To plot data with categorical "
"axes, consider using the `heatmap` function from "
"the `seaborn` statistical plotting library." % axis
"the `seaborn` statistical plotting library."
)

# If logscale, compute the intervals in the logarithmic space
Expand Down
3 changes: 1 addition & 2 deletions xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ def __call__(self, dsk, keys, **kwargs):
self.total_computes += 1
if self.total_computes > self.max_computes:
raise RuntimeError(
"Too many computes. Total: %d > max: %d."
% (self.total_computes, self.max_computes)
f"Too many computes. Total: {self.total_computes} > max: {self.max_computes}."
)
return dask.get(dsk, keys, **kwargs)

Expand Down
5 changes: 2 additions & 3 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,15 @@ def test_unicode_data(self) -> None:

byteorder = "<" if sys.byteorder == "little" else ">"
expected = dedent(
"""\
f"""\
<xarray.Dataset> Size: 12B
Dimensions: (foø: 1)
Coordinates:
* foø (foø) %cU3 12B %r
* foø (foø) {byteorder}U3 12B {'ba®'!r}
Data variables:
*empty*
Attributes:
å: ∑"""
% (byteorder, "ba®")
)
actual = str(data)
assert expected == actual
Expand Down
14 changes: 6 additions & 8 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_diff_array_repr(self) -> None:

byteorder = "<" if sys.byteorder == "little" else ">"
expected = dedent(
"""\
f"""\
Left and right DataArray objects are not identical
Differing dimensions:
(x: 2, y: 3) != (x: 2)
Expand All @@ -306,8 +306,8 @@ def test_diff_array_repr(self) -> None:
R
array([1, 2], dtype=int64)
Differing coordinates:
L * x (x) %cU1 8B 'a' 'b'
R * x (x) %cU1 8B 'a' 'c'
L * x (x) {byteorder}U1 8B 'a' 'b'
R * x (x) {byteorder}U1 8B 'a' 'c'
Coordinates only on the left object:
* y (y) int64 24B 1 2 3
Coordinates only on the right object:
Expand All @@ -317,7 +317,6 @@ def test_diff_array_repr(self) -> None:
R units: kg
Attributes only on the left object:
description: desc"""
% (byteorder, byteorder)
)

actual = formatting.diff_array_repr(da_a, da_b, "identical")
Expand Down Expand Up @@ -496,15 +495,15 @@ def test_diff_dataset_repr(self) -> None:

byteorder = "<" if sys.byteorder == "little" else ">"
expected = dedent(
"""\
f"""\
Left and right Dataset objects are not identical
Differing dimensions:
(x: 2, y: 3) != (x: 2)
Differing coordinates:
L * x (x) %cU1 8B 'a' 'b'
L * x (x) {byteorder}U1 8B 'a' 'b'
Differing variable attributes:
foo: bar
R * x (x) %cU1 8B 'a' 'c'
R * x (x) {byteorder}U1 8B 'a' 'c'
Differing variable attributes:
source: 0
foo: baz
Expand All @@ -522,7 +521,6 @@ def test_diff_dataset_repr(self) -> None:
R title: newtitle
Attributes only on the left object:
description: desc"""
% (byteorder, byteorder)
)

actual = formatting.diff_dataset_repr(ds_a, ds_b, "identical")
Expand Down

0 comments on commit 20fe30d

Please sign in to comment.