Skip to content

Commit efe5751

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 44ab465 commit efe5751

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

xarray/backends/api.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,12 +1926,11 @@ def to_netcdf(
19261926
if engine is None:
19271927
engine = _get_default_engine(path_or_file)
19281928
path_or_file = _normalize_path(path_or_file)
1929-
else: # file-like object
1930-
if engine not in ("scipy", "h5netcdf"):
1931-
# Requested engine is not compatible with writing to a file-like object.
1932-
# Ideally we would raise an error, but for backwards-compatibility with
1933-
# old behaviour we overwrite the engine to scipy.
1934-
engine = "scipy"
1929+
elif engine not in ("scipy", "h5netcdf"):
1930+
# Requested engine is not compatible with writing to a file-like object.
1931+
# Ideally we would raise an error, but for backwards-compatibility with
1932+
# old behaviour we overwrite the engine to scipy.
1933+
engine = "scipy"
19351934

19361935
# validate Dataset keys, DataArray names, and attr keys/values
19371936
_validate_dataset_names(dataset)

xarray/core/datatree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import functools
44
import io
55
import itertools
6-
from os import PathLike
76
import textwrap
87
from collections import ChainMap
98
from collections.abc import (
@@ -14,6 +13,7 @@
1413
Mapping,
1514
)
1615
from html import escape
16+
from os import PathLike
1717
from typing import (
1818
TYPE_CHECKING,
1919
Any,

xarray/core/datatree_io.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
from collections.abc import Mapping
43
import io
4+
from collections.abc import Mapping
55
from os import PathLike
66
from typing import TYPE_CHECKING, Any, Literal, get_args, overload
77

@@ -14,6 +14,7 @@
1414
if TYPE_CHECKING:
1515
from xarray.core.types import ZarrStoreLike
1616

17+
1718
@overload
1819
def _datatree_to_netcdf(
1920
dt: DataTree,
@@ -29,6 +30,7 @@ def _datatree_to_netcdf(
2930
**kwargs,
3031
) -> bytes: ...
3132

33+
3234
@overload
3335
def _datatree_to_netcdf(
3436
dt: DataTree,
@@ -44,6 +46,7 @@ def _datatree_to_netcdf(
4446
**kwargs,
4547
) -> None: ...
4648

49+
4750
def _datatree_to_netcdf(
4851
dt: DataTree,
4952
filepath: str | PathLike | io.IOBase | None = None,
@@ -67,7 +70,9 @@ def _datatree_to_netcdf(
6770
raise ValueError("DataTree.to_netcdf only supports the NETCDF4 format")
6871

6972
if engine not in [None, *get_args(T_DataTreeNetcdfEngine)]:
70-
raise ValueError("DataTree.to_netcdf only supports the netcdf4 and h5netcdf engines")
73+
raise ValueError(
74+
"DataTree.to_netcdf only supports the netcdf4 and h5netcdf engines"
75+
)
7176

7277
if engine is None:
7378
engine = "h5netcdf"

xarray/tests/test_backends_datatree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,13 @@ def test_roundtrip_via_bytes(self, simple_datatree):
546546

547547
def test_roundtrip_using_filelike_object(self, tmpdir, simple_datatree):
548548
original_dt = simple_datatree
549-
filepath = tmpdir + '/test.nc'
549+
filepath = tmpdir + "/test.nc"
550550
# h5py requires both read and write access when writing, it will
551551
# work with file-like objects provided they support both, and are
552552
# seekable.
553-
with open(filepath, 'wb+') as file:
553+
with open(filepath, "wb+") as file:
554554
original_dt.to_netcdf(file, engine=self.engine)
555-
with open(filepath, 'rb') as file:
555+
with open(filepath, "rb") as file:
556556
roundtrip_dt = open_datatree(file, engine=self.engine)
557557
assert_equal(original_dt, roundtrip_dt)
558558

0 commit comments

Comments
 (0)