Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for keyword arguments passed to engines when opening a datatree #9283

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
63 changes: 63 additions & 0 deletions xarray/tests/test_backends_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ def test_netcdf_encoding(self, tmpdir, simple_datatree):
@requires_netCDF4
class TestNetCDF4DatatreeIO(DatatreeIOBase):
engine: T_DataTreeNetcdfEngine | None = "netcdf4"
keywords: [
{"mask_and_scale":True},
{"decode_times":True},
{"concat_characters":True},
{"decode_coords":True},
{"drop_variables": str | Iterable[str] | None : None},
{"use_cftime":None},
{"decode_timedelta":None},
{"group": str | Iterable[str] | Callable | None = None,},
{"mode":"r"},
{"format":"NETCDF4"},
{"clobber":True},
{"diskless":False},
{"persist":False},
{"lock":None},
{"autoclose":False}
] | None = {}

def test_open_datatree(self, unaligned_datatree_nc) -> None:
"""Test if `open_datatree` fails to open a netCDF4 with an unaligned group hierarchy."""
Expand Down Expand Up @@ -241,11 +258,57 @@ def test_open_groups_to_dict(self, tmpdir) -> None:
@requires_h5netcdf
class TestH5NetCDFDatatreeIO(DatatreeIOBase):
engine: T_DataTreeNetcdfEngine | None = "h5netcdf"
keywords: [
{"mask_and_scale":True},
{"decode_times":True},
{"concat_characters":True},
{"decode_coords":True},
{"drop_variables": str | Iterable[str] | None : None},
{"use_cftime":None},
{"decode_timedelta":None},
{"format":None},
{"group":None},
{"lock":None},
{"invalid_netcdf":None},
{"phony_dims":None},
{"decode_vlen_strings":True},
{"driver":None},
{"driver_kwds":None}
] | None = {}


def test_pass_engine_kwargs(self, tmpdir, simple_datatree):
filepath = tmpdir / "test.nc"
original_dt = simple_datatree
original_dt.to_netcdf(filepath, engine=self.engine)

roundtrip_dt = open_datatree(filepath, engine=self.engine, phony_dims="sort")
assert_equal(original_dt, roundtrip_dt)



@requires_zarr
class TestZarrDatatreeIO:
engine = "zarr"
keywords: [
{"mask_and_scale":True},
{"decode_times":True},
{"concat_characters":True},
{"decode_coords":True},
{"drop_variables":str | Iterable[str] | None = None},
{"use_cftime":None},
{"decode_timedelta":None},
{"group":str | Iterable[str] | Callable | None = None},
{"mode":"r"},
{"synchronizer":None},
{"consolidated":None},
{"chunk_store":None},
{"storage_options":None},
{"stacklevel":3}
{"zarr_version":None},
{"store":None},
{"engine":None}
] | None = {}

def test_to_zarr(self, tmpdir, simple_datatree):
filepath = tmpdir / "test.zarr"
Expand Down
Loading