MCPcopy Index your code
hub / github.com/pydata/xarray / test_encode_cf_datetime_units_change

Function test_encode_cf_datetime_units_change

xarray/tests/test_coding_times.py:1720–1740  ·  view source on GitHub ↗
(use_cftime, use_dask)

Source from the content-addressed store, hash-verified

1718)
1719@pytest.mark.parametrize("use_dask", [False, pytest.param(True, marks=requires_dask)])
1720def test_encode_cf_datetime_units_change(use_cftime, use_dask) -> None:
1721 times = date_range(start="2000", freq="12h", periods=3, use_cftime=use_cftime)
1722 encoding = dict(units="days since 2000-01-01", dtype=np.dtype("int64"))
1723 variable = Variable(["time"], times, encoding=encoding)
1724
1725 if use_dask:
1726 variable = variable.chunk({"time": 1})
1727 with pytest.raises(ValueError, match="Times can't be serialized"):
1728 conventions.encode_cf_variable(variable).compute()
1729 else:
1730 with pytest.warns(UserWarning, match="Times can't be serialized"):
1731 encoded = conventions.encode_cf_variable(variable)
1732 if use_cftime:
1733 expected_units = "hours since 2000-01-01 00:00:00.000000"
1734 else:
1735 expected_units = "hours since 2000-01-01"
1736 assert encoded.attrs["units"] == expected_units
1737 decoded = conventions.decode_cf_variable(
1738 "name", encoded, decode_times=CFDatetimeCoder(use_cftime=use_cftime)
1739 )
1740 assert_equal(variable, decoded)
1741
1742
1743@pytest.mark.parametrize("use_dask", [False, pytest.param(True, marks=requires_dask)])

Callers

nothing calls this directly

Calls 7

chunkMethod · 0.95
date_rangeFunction · 0.90
VariableClass · 0.90
assert_equalFunction · 0.90
CFDatetimeCoderClass · 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…