(use_cftime, use_dask)
| 1718 | ) |
| 1719 | @pytest.mark.parametrize("use_dask", [False, pytest.param(True, marks=requires_dask)]) |
| 1720 | def 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)]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…