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

Method test_open_encodings

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

Source from the content-addressed store, hash-verified

1875 assert actual["x"].dtype == np.dtype("S4")
1876
1877 def test_open_encodings(self) -> None:
1878 # Create a netCDF file with explicit time units
1879 # and make sure it makes it into the encodings
1880 # and survives a round trip
1881 with create_tmp_file() as tmp_file:
1882 with nc4.Dataset(tmp_file, "w") as ds:
1883 ds.createDimension("time", size=10)
1884 ds.createVariable("time", np.int32, dimensions=("time",))
1885 units = "days since 1999-01-01"
1886 ds.variables["time"].setncattr("units", units)
1887 ds.variables["time"][:] = np.arange(10) + 4
1888
1889 expected = Dataset()
1890 time = pd.date_range("1999-01-05", periods=10, unit="ns")
1891 encoding = {"units": units, "dtype": np.dtype("int32")}
1892 expected["time"] = ("time", time, {}, encoding)
1893
1894 with open_dataset(tmp_file) as actual:
1895 assert_equal(actual["time"], expected["time"])
1896 actual_encoding = {
1897 k: v
1898 for k, v in actual["time"].encoding.items()
1899 if k in expected["time"].encoding
1900 }
1901 assert actual_encoding == expected["time"].encoding
1902
1903 def test_dump_encodings(self) -> None:
1904 # regression test for #709

Callers

nothing calls this directly

Calls 7

DatasetClass · 0.90
open_datasetFunction · 0.90
assert_equalFunction · 0.90
create_tmp_fileFunction · 0.85
arangeMethod · 0.80
itemsMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected