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

Function test_encode_cf_timedelta_units_change

xarray/tests/test_coding_times.py:1793–1811  ·  view source on GitHub ↗
(use_dask)

Source from the content-addressed store, hash-verified

1791
1792@pytest.mark.parametrize("use_dask", [False, pytest.param(True, marks=requires_dask)])
1793def test_encode_cf_timedelta_units_change(use_dask) -> None:
1794 timedeltas = pd.timedelta_range(start="0h", freq="12h", periods=3)
1795 encoding = dict(units="days", dtype=np.dtype("int64"))
1796 variable = Variable(["time"], timedeltas, encoding=encoding)
1797
1798 if use_dask:
1799 variable = variable.chunk({"time": 1})
1800 with pytest.raises(ValueError, match="Timedeltas can't be serialized"):
1801 conventions.encode_cf_variable(variable).compute()
1802 else:
1803 # In this case we automatically modify the encoding units to continue
1804 # encoding with integer values.
1805 with pytest.warns(UserWarning, match="Timedeltas can't be serialized"):
1806 encoded = conventions.encode_cf_variable(variable)
1807 assert encoded.attrs["units"] == "hours"
1808 decoded = conventions.decode_cf_variable(
1809 "name", encoded, decode_timedelta=CFTimedeltaCoder(time_unit="ns")
1810 )
1811 assert_equal(variable, decoded)
1812
1813
1814@pytest.mark.parametrize("use_dask", [False, pytest.param(True, marks=requires_dask)])

Callers

nothing calls this directly

Calls 6

chunkMethod · 0.95
VariableClass · 0.90
assert_equalFunction · 0.90
CFTimedeltaCoderClass · 0.85
dtypeMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…