Rewrite DataTree.to_netcdf and support netCDF4 in-memory #10624
+796
−405
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes a handful of significant changes:
DataTree.to_netcdf()
andDataTree.to_zarr()
to use lower level interfaces, rather than callingDataset
methods. This allows for properly supportingcompute=False
(and likely various other improvements).load_datatree
function, for consistentcy withload_dataset
andload_dataarray
.engine
argument inDataTree.to_netcdf()
is now set consistently withDataset.to_netcdf()
, preferringnetcdf4
toh5netcdf
.Dataset.to_netcdf()
without a target now always returns amemoryview
object, including in the case whereengine='scipy'
is used (which currently returnsbytes
). This is a breaking change, rather than merely issuing a warning as is done in Support for DataTree.to_netcdf to write to a file-like object or bytes #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 (becausenetcdf4
is preferred to thescipy
backend) and (3) restoring previous behavior is easy (by wrapping the memoryview withbytes()
).whats-new.rst