Skip to content
forked from pydata/xarray

Commit d924d93

Browse files
Update pre-commit hooks (pydata#10021)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c252152 commit d924d93

20 files changed

+56
-65
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
- id: text-unicode-replacement-char
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
2727
# Ruff version.
28-
rev: v0.8.6
28+
rev: v0.9.4
2929
hooks:
3030
- id: ruff-format
3131
- id: ruff

xarray/backends/api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def _get_default_engine_remote_uri() -> Literal["netcdf4", "pydap"]:
104104
engine = "pydap"
105105
except ImportError as err:
106106
raise ValueError(
107-
"netCDF4 or pydap is required for accessing "
108-
"remote datasets via OPeNDAP"
107+
"netCDF4 or pydap is required for accessing remote datasets via OPeNDAP"
109108
) from err
110109
return engine
111110

@@ -1669,8 +1668,7 @@ def open_mfdataset(
16691668
)
16701669
else:
16711670
raise ValueError(
1672-
f"{combine} is an invalid option for the keyword argument"
1673-
" ``combine``"
1671+
f"{combine} is an invalid option for the keyword argument ``combine``"
16741672
)
16751673
except ValueError:
16761674
for ds in datasets:

xarray/backends/h5netcdf_.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def __init__(self, manager, group=None, mode=None, lock=HDF5_LOCK, autoclose=Fal
119119
else:
120120
if type(manager) is not h5netcdf.File:
121121
raise ValueError(
122-
"must supply a h5netcdf.File if the group "
123-
"argument is provided"
122+
"must supply a h5netcdf.File if the group argument is provided"
124123
)
125124
root = manager
126125
manager = DummyFileManager(root)

xarray/coding/cftimeindex.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,18 @@ def __repr__(self):
294294
offset=offset,
295295
first_row_offset=offset,
296296
)
297-
datastr = "\n".join([front_str, f"{' '*offset}...", end_str])
297+
datastr = "\n".join([front_str, f"{' ' * offset}...", end_str])
298298

299299
attrs_str = format_attrs(self)
300300
# oneliner only if smaller than display_width
301301
full_repr_str = f"{klass_name}([{datastr}], {attrs_str})"
302302
if len(full_repr_str) > display_width:
303303
# if attrs_str too long, one per line
304304
if len(attrs_str) >= display_width - offset:
305-
attrs_str = attrs_str.replace(",", f",\n{' '*(offset-2)}")
306-
full_repr_str = f"{klass_name}([{datastr}],\n{' '*(offset-1)}{attrs_str})"
305+
attrs_str = attrs_str.replace(",", f",\n{' ' * (offset - 2)}")
306+
full_repr_str = (
307+
f"{klass_name}([{datastr}],\n{' ' * (offset - 1)}{attrs_str})"
308+
)
307309

308310
return full_repr_str
309311

xarray/core/common.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def get_squeeze_dims(
412412

413413
if any(xarray_obj.sizes[k] > 1 for k in dim):
414414
raise ValueError(
415-
"cannot select a dimension to squeeze out "
416-
"which has length greater than one"
415+
"cannot select a dimension to squeeze out which has length greater than one"
417416
)
418417
return dim
419418

xarray/core/dataarray.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3512,8 +3512,7 @@ def fillna(self, value: Any) -> Self:
35123512
"""
35133513
if utils.is_dict_like(value):
35143514
raise TypeError(
3515-
"cannot provide fill value as a dictionary with "
3516-
"fillna on a DataArray"
3515+
"cannot provide fill value as a dictionary with fillna on a DataArray"
35173516
)
35183517
out = ops.fillna(self, value)
35193518
return out
@@ -4537,8 +4536,7 @@ def from_dict(cls, d: Mapping[str, Any]) -> Self:
45374536
}
45384537
except KeyError as e:
45394538
raise ValueError(
4540-
"cannot convert dict when coords are missing the key "
4541-
f"'{e.args[0]}'"
4539+
f"cannot convert dict when coords are missing the key '{e.args[0]}'"
45424540
) from e
45434541
try:
45444542
data = d["data"]

xarray/core/dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6478,7 +6478,7 @@ def transpose(
64786478
if (len(dim) > 0) and (isinstance(dim[0], list)):
64796479
list_fix = [f"{x!r}" if isinstance(x, str) else f"{x}" for x in dim[0]]
64806480
raise TypeError(
6481-
f'transpose requires dim to be passed as multiple arguments. Expected `{", ".join(list_fix)}`. Received `{dim[0]}` instead'
6481+
f"transpose requires dim to be passed as multiple arguments. Expected `{', '.join(list_fix)}`. Received `{dim[0]}` instead"
64826482
)
64836483

64846484
# Use infix_dims to check once for missing dimensions

xarray/core/datatree.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ def set_close(self, close: Callable[[], None] | None) -> None:
276276

277277
def close(self) -> None:
278278
raise AttributeError(
279-
"cannot close a DatasetView(). Close the associated DataTree node "
280-
"instead"
279+
"cannot close a DatasetView(). Close the associated DataTree node instead"
281280
)
282281

283282
# FIXME https://github.com/python/mypy/issues/7328

xarray/core/datatree_render.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def __init__(self, vertical: str, cont: str, end: str):
3131
self.vertical = vertical
3232
self.cont = cont
3333
self.end = end
34-
assert (
35-
len(cont) == len(vertical) == len(end)
36-
), f"'{vertical}', '{cont}' and '{end}' need to have equal length"
34+
assert len(cont) == len(vertical) == len(end), (
35+
f"'{vertical}', '{cont}' and '{end}' need to have equal length"
36+
)
3737

3838
@property
3939
def empty(self) -> str:

xarray/core/formatting_html.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ def summarize_attrs(attrs) -> str:
7272
def _icon(icon_name) -> str:
7373
# icon_name should be defined in xarray/static/html/icon-svg-inline.html
7474
return (
75-
f"<svg class='icon xr-{icon_name}'>"
76-
f"<use xlink:href='#{icon_name}'>"
77-
"</use>"
78-
"</svg>"
75+
f"<svg class='icon xr-{icon_name}'><use xlink:href='#{icon_name}'></use></svg>"
7976
)
8077

8178

xarray/core/treenode.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def _attach(self, parent: Tree | None, child_name: str | None = None) -> None:
151151

152152
self._pre_attach(parent, child_name)
153153
parentchildren = parent._children
154-
assert not any(
155-
child is self for child in parentchildren
156-
), "Tree is corrupt."
154+
assert not any(child is self for child in parentchildren), (
155+
"Tree is corrupt."
156+
)
157157
parentchildren[child_name] = self
158158
self._parent = parent
159159
self._post_attach(parent, child_name)

xarray/core/variable.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ def _validate_indexers(self, key):
651651
)
652652
if k.ndim > 1:
653653
raise IndexError(
654-
f"{k.ndim}-dimensional boolean indexing is "
655-
"not supported. "
654+
f"{k.ndim}-dimensional boolean indexing is not supported. "
656655
)
657656
if is_duck_dask_array(k.data):
658657
raise KeyError(

xarray/testing/assertions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ def assert_identical(a, b):
169169
if isinstance(a, Variable):
170170
assert a.identical(b), formatting.diff_array_repr(a, b, "identical")
171171
elif isinstance(a, DataArray):
172-
assert (
173-
a.name == b.name
174-
), f"DataArray names are different. L: {a.name}, R: {b.name}"
172+
assert a.name == b.name, (
173+
f"DataArray names are different. L: {a.name}, R: {b.name}"
174+
)
175175
assert a.identical(b), formatting.diff_array_repr(a, b, "identical")
176176
elif isinstance(a, Dataset | Variable):
177177
assert a.identical(b), formatting.diff_dataset_repr(a, b, "identical")

xarray/tests/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ def format_record(record) -> str:
269269
def assert_no_warnings():
270270
with warnings.catch_warnings(record=True) as record:
271271
yield record
272-
assert (
273-
len(record) == 0
274-
), f"Got {len(record)} unexpected warning(s): {[format_record(r) for r in record]}"
272+
assert len(record) == 0, (
273+
f"Got {len(record)} unexpected warning(s): {[format_record(r) for r in record]}"
274+
)
275275

276276

277277
# Internal versions of xarray's test functions that validate additional
@@ -320,7 +320,7 @@ def create_test_data(
320320
obj["dim2"] = ("dim2", 0.5 * np.arange(_dims["dim2"]))
321321
if _dims["dim3"] > 26:
322322
raise RuntimeError(
323-
f'Not enough letters for filling this dimension size ({_dims["dim3"]})'
323+
f"Not enough letters for filling this dimension size ({_dims['dim3']})"
324324
)
325325
obj["dim3"] = ("dim3", list(string.ascii_lowercase[0 : _dims["dim3"]]))
326326
obj["time"] = (

xarray/tests/test_backends_datatree.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ def test_open_groups_chunks(self, tmpdir) -> None:
301301
dict_of_datasets = open_groups(filepath, engine="netcdf4", chunks=chunks)
302302

303303
for path, ds in dict_of_datasets.items():
304-
assert {
305-
k: max(vs) for k, vs in ds.chunksizes.items()
306-
} == chunks, f"unexpected chunking for {path}"
304+
assert {k: max(vs) for k, vs in ds.chunksizes.items()} == chunks, (
305+
f"unexpected chunking for {path}"
306+
)
307307

308308
for ds in dict_of_datasets.values():
309309
ds.close()
@@ -587,9 +587,9 @@ def test_open_groups_chunks(self, tmpdir) -> None:
587587
dict_of_datasets = open_groups(filepath, engine="zarr", chunks=chunks)
588588

589589
for path, ds in dict_of_datasets.items():
590-
assert {
591-
k: max(vs) for k, vs in ds.chunksizes.items()
592-
} == chunks, f"unexpected chunking for {path}"
590+
assert {k: max(vs) for k, vs in ds.chunksizes.items()} == chunks, (
591+
f"unexpected chunking for {path}"
592+
)
593593

594594
for ds in dict_of_datasets.values():
595595
ds.close()

xarray/tests/test_dataarray.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1792,12 +1792,12 @@ def test_reindex_empty_array_dtype(self) -> None:
17921792
x = xr.DataArray([], dims=("x",), coords={"x": []}).astype("float32")
17931793
y = x.reindex(x=[1.0, 2.0])
17941794

1795-
assert (
1796-
x.dtype == y.dtype
1797-
), "Dtype of reindexed DataArray should match dtype of the original DataArray"
1798-
assert (
1799-
y.dtype == np.float32
1800-
), "Dtype of reindexed DataArray should remain float32"
1795+
assert x.dtype == y.dtype, (
1796+
"Dtype of reindexed DataArray should match dtype of the original DataArray"
1797+
)
1798+
assert y.dtype == np.float32, (
1799+
"Dtype of reindexed DataArray should remain float32"
1800+
)
18011801

18021802
def test_rename(self) -> None:
18031803
da = xr.DataArray(

xarray/tests/test_dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def test_unicode_data(self) -> None:
395395
<xarray.Dataset> Size: 12B
396396
Dimensions: (foø: 1)
397397
Coordinates:
398-
* foø (foø) {byteorder}U3 12B {'ba®'!r}
398+
* foø (foø) {byteorder}U3 12B {"ba®"!r}
399399
Data variables:
400400
*empty*
401401
Attributes:

xarray/tests/test_datatree.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2338,15 +2338,15 @@ def fn(x):
23382338
assert_identical(actual, expected)
23392339

23402340
assert actual.chunksizes == original_chunksizes, "chunksizes were modified"
2341-
assert (
2342-
tree.chunksizes == original_chunksizes
2343-
), "original chunksizes were modified"
2344-
assert all(
2345-
d == 1 for d in actual_hlg_depths.values()
2346-
), "unexpected dask graph depth"
2347-
assert all(
2348-
d == 2 for d in original_hlg_depths.values()
2349-
), "original dask graph was modified"
2341+
assert tree.chunksizes == original_chunksizes, (
2342+
"original chunksizes were modified"
2343+
)
2344+
assert all(d == 1 for d in actual_hlg_depths.values()), (
2345+
"unexpected dask graph depth"
2346+
)
2347+
assert all(d == 2 for d in original_hlg_depths.values()), (
2348+
"original dask graph was modified"
2349+
)
23502350

23512351
def test_chunk(self):
23522352
ds1 = xr.Dataset({"a": ("x", np.arange(10))})

xarray/tests/test_plugins.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ def test_lazy_import() -> None:
253253
if pkg.startswith(mod):
254254
is_imported.add(mod)
255255
break
256-
assert (
257-
len(is_imported) == 0
258-
), f"{is_imported} have been imported but should be lazy"
256+
assert len(is_imported) == 0, (
257+
f"{is_imported} have been imported but should be lazy"
258+
)
259259

260260
finally:
261261
# restore original

xarray/util/print_versions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def get_sys_info():
4949
("machine", f"{machine}"),
5050
("processor", f"{processor}"),
5151
("byteorder", f"{sys.byteorder}"),
52-
("LC_ALL", f'{os.environ.get("LC_ALL", "None")}'),
53-
("LANG", f'{os.environ.get("LANG", "None")}'),
52+
("LC_ALL", f"{os.environ.get('LC_ALL', 'None')}"),
53+
("LANG", f"{os.environ.get('LANG', 'None')}"),
5454
("LOCALE", f"{locale.getlocale()}"),
5555
]
5656
)

0 commit comments

Comments
 (0)