(self)
| 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 |
nothing calls this directly
no test coverage detected