Skip to content

Commit 20fe30d

Browse files
Apply ruff/pyupgrade rule UP031
UP031 Use format specifiers instead of percent format
1 parent 0bddbd6 commit 20fe30d

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

asv_bench/benchmarks/dataset_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def make_ds(self, nfiles=10):
305305
ds.attrs = {"history": "created for xarray benchmarking"}
306306

307307
self.ds_list.append(ds)
308-
self.filenames_list.append("test_netcdf_%i.nc" % i)
308+
self.filenames_list.append(f"test_netcdf_{i}.nc")
309309

310310

311311
class IOWriteMultipleNetCDF3(IOMultipleNetCDF):

xarray/core/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7615,7 +7615,7 @@ def from_dataframe(cls, dataframe: pd.DataFrame, sparse: bool = False) -> Self:
76157615

76167616
if isinstance(idx, pd.MultiIndex):
76177617
dims = tuple(
7618-
name if name is not None else "level_%i" % n # type: ignore[redundant-expr]
7618+
name if name is not None else f"level_{n}" # type: ignore[redundant-expr]
76197619
for n, name in enumerate(idx.names)
76207620
)
76217621
for dim, lev in zip(dims, idx.levels, strict=True):

xarray/plot/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,11 @@ def _infer_interval_breaks(coord, axis=0, scale=None, check_monotonic=False):
869869
if check_monotonic and not _is_monotonic(coord, axis=axis):
870870
raise ValueError(
871871
"The input coordinate is not sorted in increasing "
872-
"order along axis %d. This can lead to unexpected "
872+
f"order along axis {axis}. This can lead to unexpected "
873873
"results. Consider calling the `sortby` method on "
874874
"the input DataArray. To plot data with categorical "
875875
"axes, consider using the `heatmap` function from "
876-
"the `seaborn` statistical plotting library." % axis
876+
"the `seaborn` statistical plotting library."
877877
)
878878

879879
# If logscale, compute the intervals in the logarithmic space

xarray/tests/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ def __call__(self, dsk, keys, **kwargs):
210210
self.total_computes += 1
211211
if self.total_computes > self.max_computes:
212212
raise RuntimeError(
213-
"Too many computes. Total: %d > max: %d."
214-
% (self.total_computes, self.max_computes)
213+
f"Too many computes. Total: {self.total_computes} > max: {self.max_computes}."
215214
)
216215
return dask.get(dsk, keys, **kwargs)
217216

xarray/tests/test_dataset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,15 @@ def test_unicode_data(self) -> None:
388388

389389
byteorder = "<" if sys.byteorder == "little" else ">"
390390
expected = dedent(
391-
"""\
391+
f"""\
392392
<xarray.Dataset> Size: 12B
393393
Dimensions: (foø: 1)
394394
Coordinates:
395-
* foø (foø) %cU3 12B %r
395+
* foø (foø) {byteorder}U3 12B {'ba®'!r}
396396
Data variables:
397397
*empty*
398398
Attributes:
399399
å: ∑"""
400-
% (byteorder, "ba®")
401400
)
402401
actual = str(data)
403402
assert expected == actual

xarray/tests/test_formatting.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_diff_array_repr(self) -> None:
295295

296296
byteorder = "<" if sys.byteorder == "little" else ">"
297297
expected = dedent(
298-
"""\
298+
f"""\
299299
Left and right DataArray objects are not identical
300300
Differing dimensions:
301301
(x: 2, y: 3) != (x: 2)
@@ -306,8 +306,8 @@ def test_diff_array_repr(self) -> None:
306306
R
307307
array([1, 2], dtype=int64)
308308
Differing coordinates:
309-
L * x (x) %cU1 8B 'a' 'b'
310-
R * x (x) %cU1 8B 'a' 'c'
309+
L * x (x) {byteorder}U1 8B 'a' 'b'
310+
R * x (x) {byteorder}U1 8B 'a' 'c'
311311
Coordinates only on the left object:
312312
* y (y) int64 24B 1 2 3
313313
Coordinates only on the right object:
@@ -317,7 +317,6 @@ def test_diff_array_repr(self) -> None:
317317
R units: kg
318318
Attributes only on the left object:
319319
description: desc"""
320-
% (byteorder, byteorder)
321320
)
322321

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

497496
byteorder = "<" if sys.byteorder == "little" else ">"
498497
expected = dedent(
499-
"""\
498+
f"""\
500499
Left and right Dataset objects are not identical
501500
Differing dimensions:
502501
(x: 2, y: 3) != (x: 2)
503502
Differing coordinates:
504-
L * x (x) %cU1 8B 'a' 'b'
503+
L * x (x) {byteorder}U1 8B 'a' 'b'
505504
Differing variable attributes:
506505
foo: bar
507-
R * x (x) %cU1 8B 'a' 'c'
506+
R * x (x) {byteorder}U1 8B 'a' 'c'
508507
Differing variable attributes:
509508
source: 0
510509
foo: baz
@@ -522,7 +521,6 @@ def test_diff_dataset_repr(self) -> None:
522521
R title: newtitle
523522
Attributes only on the left object:
524523
description: desc"""
525-
% (byteorder, byteorder)
526524
)
527525

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

0 commit comments

Comments
 (0)