Skip to content

Commit 6a2eddd

Browse files
authored
Encode/decode property tests use variables() (#9401)
Adds xfailed test for #9381
1 parent a04d857 commit 6a2eddd

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

Diff for: properties/test_encode_decode.py

+17-24
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,35 @@
1111
# isort: split
1212

1313
import hypothesis.extra.numpy as npst
14-
import hypothesis.strategies as st
14+
import numpy as np
1515
from hypothesis import given
1616

1717
import xarray as xr
18-
19-
an_array = npst.arrays(
20-
dtype=st.one_of(
21-
npst.unsigned_integer_dtypes(), npst.integer_dtypes(), npst.floating_dtypes()
22-
),
23-
shape=npst.array_shapes(max_side=3), # max_side specified for performance
24-
)
18+
from xarray.testing.strategies import variables
2519

2620

2721
@pytest.mark.slow
28-
@given(st.data(), an_array)
29-
def test_CFMask_coder_roundtrip(data, arr) -> None:
30-
names = data.draw(
31-
st.lists(st.text(), min_size=arr.ndim, max_size=arr.ndim, unique=True).map(
32-
tuple
33-
)
34-
)
35-
original = xr.Variable(names, arr)
22+
@given(original=variables())
23+
def test_CFMask_coder_roundtrip(original) -> None:
3624
coder = xr.coding.variables.CFMaskCoder()
3725
roundtripped = coder.decode(coder.encode(original))
3826
xr.testing.assert_identical(original, roundtripped)
3927

4028

29+
@pytest.mark.xfail
30+
@pytest.mark.slow
31+
@given(var=variables(dtype=npst.floating_dtypes()))
32+
def test_CFMask_coder_decode(var) -> None:
33+
var[0] = -99
34+
var.attrs["_FillValue"] = -99
35+
coder = xr.coding.variables.CFMaskCoder()
36+
decoded = coder.decode(var)
37+
assert np.isnan(decoded[0])
38+
39+
4140
@pytest.mark.slow
42-
@given(st.data(), an_array)
43-
def test_CFScaleOffset_coder_roundtrip(data, arr) -> None:
44-
names = data.draw(
45-
st.lists(st.text(), min_size=arr.ndim, max_size=arr.ndim, unique=True).map(
46-
tuple
47-
)
48-
)
49-
original = xr.Variable(names, arr)
41+
@given(original=variables())
42+
def test_CFScaleOffset_coder_roundtrip(original) -> None:
5043
coder = xr.coding.variables.CFScaleOffsetCoder()
5144
roundtripped = coder.decode(coder.encode(original))
5245
xr.testing.assert_identical(original, roundtripped)

0 commit comments

Comments
 (0)