Skip to content

Commit

Permalink
Add regression test for pydata#9134
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed Sep 15, 2024
1 parent eb0d247 commit d04b1ca
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,3 +1598,20 @@ def test_encode_cf_timedelta_casting_value_error(use_dask) -> None:
assert encoded.attrs["units"] == "hours"
decoded = conventions.decode_cf_variable("name", encoded)
assert_equal(variable, decoded)


@pytest.mark.parametrize("use_dask", [False, pytest.param(True, marks=requires_dask)])
def test_encode_cf_timedelta_small_dtype_missing_value(use_dask):
# Regression test for GitHub issue #9134
timedeltas = np.array([1, 2, "NaT", 4], dtype="timedelta64[D]").astype(
"timedelta64[ns]"
)
encoding = dict(units="days", dtype=np.dtype("int16"), _FillValue=np.int16(-1))
variable = Variable(["time"], timedeltas, encoding=encoding)

if use_dask:
variable = variable.chunk({"time": 1})

encoded = conventions.encode_cf_variable(variable)
decoded = conventions.decode_cf_variable("name", encoded)
assert_equal(variable, decoded)

0 comments on commit d04b1ca

Please sign in to comment.