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