Skip to content

Commit b6310e4

Browse files
committed
use scale_factor/add_offset in tests as specified by cf conventions
1 parent 66628fc commit b6310e4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

xarray/tests/test_backends.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def create_masked_and_scaled_data(dtype: type[np.number] = np.float32) -> Datase
142142
x = np.array([np.nan, np.nan, 10, 10.1, 10.2], dtype=dtype)
143143
encoding = {
144144
"_FillValue": -1,
145-
"add_offset": 10,
145+
"add_offset": dtype(10),
146146
"scale_factor": dtype(0.1),
147147
"dtype": "i2",
148148
}
@@ -152,7 +152,7 @@ def create_masked_and_scaled_data(dtype: type[np.number] = np.float32) -> Datase
152152
def create_encoded_masked_and_scaled_data(
153153
dtype: type[np.number] = np.float32,
154154
) -> Dataset:
155-
attributes = {"_FillValue": -1, "add_offset": 10, "scale_factor": dtype(0.1)}
155+
attributes = {"_FillValue": -1, "add_offset": dtype(10), "scale_factor": dtype(0.1)}
156156
return Dataset(
157157
{"x": ("t", np.array([-1, -1, 0, 1, 2], dtype=np.int16), attributes)}
158158
)
@@ -165,7 +165,7 @@ def create_unsigned_masked_scaled_data(
165165
"_FillValue": 255,
166166
"_Unsigned": "true",
167167
"dtype": "i1",
168-
"add_offset": 10,
168+
"add_offset": dtype(10),
169169
"scale_factor": dtype(0.1),
170170
}
171171
x = np.array([10.0, 10.1, 22.7, 22.8, np.nan], dtype=dtype)
@@ -180,7 +180,7 @@ def create_encoded_unsigned_masked_scaled_data(
180180
attributes = {
181181
"_FillValue": -1,
182182
"_Unsigned": "true",
183-
"add_offset": 10,
183+
"add_offset": dtype(10),
184184
"scale_factor": dtype(0.1),
185185
}
186186
# Create unsigned data corresponding to [0, 1, 127, 128, 255] unsigned
@@ -195,7 +195,7 @@ def create_bad_unsigned_masked_scaled_data(
195195
"_FillValue": 255,
196196
"_Unsigned": True,
197197
"dtype": "i1",
198-
"add_offset": 10,
198+
"add_offset": dtype(0),
199199
"scale_factor": dtype(0.1),
200200
}
201201
x = np.array([10.0, 10.1, 22.7, 22.8, np.nan], dtype=dtype)
@@ -210,7 +210,7 @@ def create_bad_encoded_unsigned_masked_scaled_data(
210210
attributes = {
211211
"_FillValue": -1,
212212
"_Unsigned": True,
213-
"add_offset": 10,
213+
"add_offset": dtype(10),
214214
"scale_factor": dtype(0.1),
215215
}
216216
# Create signed data corresponding to [0, 1, 127, 128, 255] unsigned
@@ -225,7 +225,7 @@ def create_signed_masked_scaled_data(
225225
"_FillValue": -127,
226226
"_Unsigned": "false",
227227
"dtype": "i1",
228-
"add_offset": 10,
228+
"add_offset": dtype(10),
229229
"scale_factor": dtype(0.1),
230230
}
231231
x = np.array([-1.0, 10.1, 22.7, np.nan], dtype=dtype)
@@ -240,7 +240,7 @@ def create_encoded_signed_masked_scaled_data(
240240
attributes = {
241241
"_FillValue": -127,
242242
"_Unsigned": "false",
243-
"add_offset": 10,
243+
"add_offset": dtype(10),
244244
"scale_factor": dtype(0.1),
245245
}
246246
# Create signed data corresponding to [0, 1, 127, 128, 255] unsigned
@@ -1564,7 +1564,7 @@ def test_mask_and_scale(self, dtype) -> None:
15641564
nc.createVariable("x", "int16", ("t",), fill_value=-1)
15651565
v = nc.variables["x"]
15661566
v.set_auto_maskandscale(False)
1567-
v.add_offset = 10
1567+
v.add_offset = dtype(10)
15681568
v.scale_factor = dtype(0.1)
15691569
v[:] = np.array([-1, -1, 0, 1, 2])
15701570

0 commit comments

Comments
 (0)