Skip to content

Commit 86563b9

Browse files
committed
Rewrite DataTree.to_netcdf and support netCDF4 in-memory
This PR includes a handful of significant changes: 1. It refactors the internal structure of `DataTree.to_netcdf()` and `DataTree.to_zarr()` to use lower level interfaces, rather than calling `Dataset` methods. This allows for properly supporting `compute=False` (and likely various other improvements). 2. Reading and writing in-memory data with netCDF4-python is now supported, including DataTree. 3. The `engine` argument in `DataTree.to_netcdf()` is now set consistently with `Dataset.to_netcdf()`, preferring `netcdf4` to `h5netcdf`. 3. Calling `Dataset.to_netcdf()` without a target now always returns a `memoryview` object, *including* in the case where `engine='scipy'` is used (which currently returns `bytes`). This is a breaking change, rather than merely issuing a warning as is done in #10571. I believe it probably makes sense to do as a this breaking change because (1) it offers significant performance benefits, (2) the default behavior without specifying an engine will already change (because `netcdf4` is preferred to the `scipy` backend) and (3) restoring previous behavior is easy (by wrapping the memoryview with `bytes()`). mypy
1 parent ea9f02b commit 86563b9

16 files changed

+796
-405
lines changed

xarray/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from xarray.backends.api import (
55
load_dataarray,
66
load_dataset,
7+
load_datatree,
78
open_dataarray,
89
open_dataset,
910
open_datatree,
@@ -96,6 +97,7 @@
9697
"infer_freq",
9798
"load_dataarray",
9899
"load_dataset",
100+
"load_datatree",
99101
"map_blocks",
100102
"map_over_datasets",
101103
"merge",

0 commit comments

Comments
 (0)