Skip to content

Commit 0176558

Browse files
pre-commit-ci[bot]mjwillson
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7b2d8aa commit 0176558

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

xarray/backends/api.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,14 +1926,13 @@ 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-
emit_user_level_warning(
1932-
f"Requested {engine=} is not compatible with writing to a file-like object. "
1933-
"This will raise an error in the future, for now defaulting to engine='scipy'.",
1934-
FutureWarning,
1935-
)
1936-
engine = "scipy"
1929+
elif engine not in ("scipy", "h5netcdf"):
1930+
emit_user_level_warning(
1931+
f"Requested {engine=} is not compatible with writing to a file-like object. "
1932+
"This will raise an error in the future, for now defaulting to engine='scipy'.",
1933+
FutureWarning,
1934+
)
1935+
engine = "scipy"
19371936

19381937
# validate Dataset keys, DataArray names, and attr keys/values
19391938
_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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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
6-
from typing import TYPE_CHECKING, Any, Literal, get_args, overload
6+
from typing import TYPE_CHECKING, Any, Literal, get_args
77

88
from xarray.core.datatree import DataTree
99
from xarray.core.types import NetcdfWriteModes, ZarrWriteModes
@@ -14,6 +14,7 @@
1414
if TYPE_CHECKING:
1515
from xarray.core.types import ZarrStoreLike
1616

17+
1718
def _datatree_to_netcdf(
1819
dt: DataTree,
1920
filepath: str | PathLike | io.IOBase | None = None,
@@ -37,7 +38,9 @@ def _datatree_to_netcdf(
3738
raise ValueError("DataTree.to_netcdf only supports the NETCDF4 format")
3839

3940
if engine not in [None, *get_args(T_DataTreeNetcdfEngine)]:
40-
raise ValueError("DataTree.to_netcdf only supports the netcdf4 and h5netcdf engines")
41+
raise ValueError(
42+
"DataTree.to_netcdf only supports the netcdf4 and h5netcdf engines"
43+
)
4144

4245
if engine is None:
4346
engine = "h5netcdf"

xarray/tests/test_backends_datatree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,13 @@ def test_roundtrip_via_bytes_engine_specified(self, simple_datatree):
551551

552552
def test_roundtrip_using_filelike_object(self, tmpdir, simple_datatree):
553553
original_dt = simple_datatree
554-
filepath = tmpdir + '/test.nc'
554+
filepath = tmpdir + "/test.nc"
555555
# h5py requires both read and write access when writing, it will
556556
# work with file-like objects provided they support both, and are
557557
# seekable.
558-
with open(filepath, 'wb+') as file:
558+
with open(filepath, "wb+") as file:
559559
original_dt.to_netcdf(file, engine=self.engine)
560-
with open(filepath, 'rb') as file:
560+
with open(filepath, "rb") as file:
561561
roundtrip_dt = open_datatree(file, engine=self.engine)
562562
assert_equal(original_dt, roundtrip_dt)
563563

0 commit comments

Comments
 (0)