MCPcopy
hub / github.com/pydata/xarray / test_netcdf_encoding

Method test_netcdf_encoding

xarray/tests/test_backends_datatree.py:252–267  ·  view source on GitHub ↗
(self, tmpdir, simple_datatree)

Source from the content-addressed store, hash-verified

250 assert "x" not in subtree.to_dataset(inherit=False).coords
251
252 def test_netcdf_encoding(self, tmpdir, simple_datatree) -> None:
253 filepath = tmpdir / "test.nc"
254 original_dt = simple_datatree
255
256 # add compression
257 comp = dict(zlib=True, complevel=9)
258 enc = {"/set2": dict.fromkeys(original_dt["/set2"].dataset.data_vars, comp)}
259
260 original_dt.to_netcdf(filepath, encoding=enc, engine=self.engine)
261 with open_datatree(filepath, engine=self.engine) as roundtrip_dt:
262 assert roundtrip_dt["/set2/a"].encoding["zlib"] == comp["zlib"]
263 assert roundtrip_dt["/set2/a"].encoding["complevel"] == comp["complevel"]
264
265 enc["/not/a/group"] = {"foo": "bar"} # type: ignore[dict-item]
266 with pytest.raises(ValueError, match=r"unexpected encoding group.*"):
267 original_dt.to_netcdf(filepath, encoding=enc, engine=self.engine)
268
269 def test_write_subgroup(self, tmpdir) -> None:
270 original_dt = DataTree.from_dict(

Callers

nothing calls this directly

Calls 2

open_datatreeFunction · 0.90
to_netcdfMethod · 0.45

Tested by

no test coverage detected