Skip to content

Commit 1c3c759

Browse files
committed
Add tests for CF scaling
1 parent 6e29afb commit 1c3c759

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

xarray/tests/test_coding.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import numpy as np
22

3+
import pytest
4+
35
import xarray as xr
46
from xarray.core.pycompat import suppress
57
from xarray.coding import variables
@@ -36,3 +38,14 @@ def test_coder_roundtrip():
3638
coder = variables.CFMaskCoder()
3739
roundtripped = coder.decode(coder.encode(original))
3840
assert_identical(original, roundtripped)
41+
42+
43+
@pytest.mark.parametrize('dtype', 'u1 u2 i1 i2 f2 f4'.split())
44+
def test_scaling_converts_to_float32(dtype):
45+
original = xr.Variable(('x',), np.arange(10, dtype=dtype),
46+
encoding=dict(scale_factor=10))
47+
coder = variables.CFScaleOffsetCoder()
48+
encoded = coder.encode(original)
49+
assert encoded.dtype == np.float32
50+
roundtripped = coder.decode(encoded)
51+
assert_identical(original, roundtripped)

0 commit comments

Comments
 (0)