Skip to content

Commit

Permalink
Silence another warning in test_backends.py (#8587)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dcherian authored Jan 5, 2024
1 parent 28fa741 commit bc2ac07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion xarray/coding/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def decode(self, variable: Variable, name: T_Name = None) -> Variable:
class UnsignedIntegerCoder(VariableCoder):
def encode(self, variable: Variable, name: T_Name = None) -> Variable:
# from netCDF best practices
# https://www.unidata.ucar.edu/software/netcdf/docs/BestPractices.html
# https://docs.unidata.ucar.edu/nug/current/best_practices.html#bp_Unsigned-Data
# "_Unsigned = "true" to indicate that
# integer data should be treated as unsigned"
if variable.encoding.get("_Unsigned", "false") == "true":
Expand Down
7 changes: 2 additions & 5 deletions xarray/tests/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ def test_decode_cf_with_conflicting_fill_missing_value() -> None:
var = Variable(
["t"], np.arange(3), {"units": "foobar", "missing_value": 0, "_FillValue": 1}
)
with warnings.catch_warnings(record=True) as w:
with pytest.warns(SerializationWarning, match="has multiple fill"):
actual = conventions.decode_cf_variable("t", var)
assert_identical(actual, expected)
assert "has multiple fill" in str(w[0].message)

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

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

def test_decode_cf_with_drop_variables(self) -> None:
original = Dataset(
Expand Down Expand Up @@ -387,7 +385,6 @@ def test_decode_cf_with_dask(self) -> None:
}
).chunk()
decoded = conventions.decode_cf(original)
print(decoded)
assert all(
isinstance(var.data, da.Array)
for name, var in decoded.variables.items()
Expand Down

0 comments on commit bc2ac07

Please sign in to comment.