Skip to content

Commit bc2ac07

Browse files
authored
Silence another warning in test_backends.py (#8587)
* Silence another warning in test_backends.py Using 255 as fillvalue for int8 arrays will not be allowed any more. Previously this overflowed to -1. Now specify that instead. On numpy 1.24.4 >>> np.array([255], dtype="i1") DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays. The conversion of 255 to int8 will fail in the future. array([-1], dtype=int8) * Silence another warning * Revert "Silence another warning in test_backends.py" This reverts commit fe15ac6.
1 parent 28fa741 commit bc2ac07

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

xarray/coding/variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def decode(self, variable: Variable, name: T_Name = None) -> Variable:
414414
class UnsignedIntegerCoder(VariableCoder):
415415
def encode(self, variable: Variable, name: T_Name = None) -> Variable:
416416
# from netCDF best practices
417-
# https://www.unidata.ucar.edu/software/netcdf/docs/BestPractices.html
417+
# https://docs.unidata.ucar.edu/nug/current/best_practices.html#bp_Unsigned-Data
418418
# "_Unsigned = "true" to indicate that
419419
# integer data should be treated as unsigned"
420420
if variable.encoding.get("_Unsigned", "false") == "true":

xarray/tests/test_conventions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ def test_decode_cf_with_conflicting_fill_missing_value() -> None:
5252
var = Variable(
5353
["t"], np.arange(3), {"units": "foobar", "missing_value": 0, "_FillValue": 1}
5454
)
55-
with warnings.catch_warnings(record=True) as w:
55+
with pytest.warns(SerializationWarning, match="has multiple fill"):
5656
actual = conventions.decode_cf_variable("t", var)
5757
assert_identical(actual, expected)
58-
assert "has multiple fill" in str(w[0].message)
5958

6059
expected = Variable(["t"], np.arange(10), {"units": "foobar"})
6160

@@ -293,10 +292,9 @@ def test_0d_int32_encoding(self) -> None:
293292
def test_decode_cf_with_multiple_missing_values(self) -> None:
294293
original = Variable(["t"], [0, 1, 2], {"missing_value": np.array([0, 1])})
295294
expected = Variable(["t"], [np.nan, np.nan, 2], {})
296-
with warnings.catch_warnings(record=True) as w:
295+
with pytest.warns(SerializationWarning, match="has multiple fill"):
297296
actual = conventions.decode_cf_variable("t", original)
298297
assert_identical(expected, actual)
299-
assert "has multiple fill" in str(w[0].message)
300298

301299
def test_decode_cf_with_drop_variables(self) -> None:
302300
original = Dataset(
@@ -387,7 +385,6 @@ def test_decode_cf_with_dask(self) -> None:
387385
}
388386
).chunk()
389387
decoded = conventions.decode_cf(original)
390-
print(decoded)
391388
assert all(
392389
isinstance(var.data, da.Array)
393390
for name, var in decoded.variables.items()

0 commit comments

Comments
 (0)