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

Method test_dump_and_open_encodings

xarray/tests/test_backends.py:1910–1927  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1908 assert actual.x.encoding["zlib"]
1909
1910 def test_dump_and_open_encodings(self) -> None:
1911 # Create a netCDF file with explicit time units
1912 # and make sure it makes it into the encodings
1913 # and survives a round trip
1914 with create_tmp_file() as tmp_file:
1915 with nc4.Dataset(tmp_file, "w") as ds:
1916 ds.createDimension("time", size=10)
1917 ds.createVariable("time", np.int32, dimensions=("time",))
1918 units = "days since 1999-01-01"
1919 ds.variables["time"].setncattr("units", units)
1920 ds.variables["time"][:] = np.arange(10) + 4
1921
1922 with open_dataset(tmp_file) as xarray_dataset:
1923 with create_tmp_file() as tmp_file2:
1924 xarray_dataset.to_netcdf(tmp_file2)
1925 with nc4.Dataset(tmp_file2, "r") as ds:
1926 assert ds.variables["time"].getncattr("units") == units
1927 assert_array_equal(ds.variables["time"], np.arange(10) + 4)
1928
1929 def test_compression_encoding_legacy(self) -> None:
1930 data = create_test_data()

Callers

nothing calls this directly

Calls 4

open_datasetFunction · 0.90
create_tmp_fileFunction · 0.85
arangeMethod · 0.80
to_netcdfMethod · 0.45

Tested by

no test coverage detected