Skip to content

Commit 4c2540d

Browse files
mathausedcherian
andauthored
fix and supress some test warnings (#10104)
* fix and supress some test warnings * supress expected cast warnings * fix duplicate dims test --------- Co-authored-by: Deepak Cherian <[email protected]>
1 parent 7a3a4c6 commit 4c2540d

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

xarray/tests/test_array_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def test_aggregation_skipna(arrays) -> None:
5151
assert_equal(actual, expected)
5252

5353

54+
# casting nan warns
55+
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast")
5456
def test_astype(arrays) -> None:
5557
np_arr, xp_arr = arrays
5658
expected = np_arr.astype(np.int64)

xarray/tests/test_backends.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,7 @@ def test_phony_dims_warning(self) -> None:
41854185
fx.create_dataset(k, data=v)
41864186
with pytest.warns(UserWarning, match="The 'phony_dims' kwarg"):
41874187
with xr.open_dataset(tmp_file, engine="h5netcdf", group="bar") as ds:
4188-
assert ds.dims == {
4188+
assert ds.sizes == {
41894189
"phony_dim_0": 5,
41904190
"phony_dim_1": 5,
41914191
"phony_dim_2": 5,
@@ -4300,7 +4300,8 @@ def test_open_fileobj(self) -> None:
43004300
# `raises_regex`?). Ref https://github.com/pydata/xarray/pull/5191
43014301
with open(tmp_file, "rb") as f:
43024302
f.seek(8)
4303-
open_dataset(f)
4303+
with open_dataset(f): # ensure file gets closed
4304+
pass
43044305

43054306

43064307
@requires_h5netcdf
@@ -6599,11 +6600,11 @@ def test_h5netcdf_storage_options() -> None:
65996600
ds2.to_netcdf(f2, engine="h5netcdf")
66006601

66016602
files = [f"file://{f}" for f in [f1, f2]]
6602-
ds = xr.open_mfdataset(
6603+
with xr.open_mfdataset(
66036604
files,
66046605
engine="h5netcdf",
66056606
concat_dim="time",
66066607
combine="nested",
66076608
storage_options={"skip_instance_cache": False},
6608-
)
6609-
assert_identical(xr.concat([ds1, ds2], dim="time"), ds)
6609+
) as ds:
6610+
assert_identical(xr.concat([ds1, ds2], dim="time"), ds)

xarray/tests/test_computation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ def test_apply_groupby_add() -> None:
634634
add(data_array.groupby("y"), data_array.groupby("x"))
635635

636636

637+
@pytest.mark.filterwarnings("ignore:Duplicate dimension names present")
637638
def test_unified_dim_sizes() -> None:
638639
assert unified_dim_sizes([xr.Variable((), 0)]) == {}
639640
assert unified_dim_sizes([xr.Variable("x", [1]), xr.Variable("x", [1])]) == {"x": 1}
@@ -646,9 +647,9 @@ def test_unified_dim_sizes() -> None:
646647
exclude_dims={"z"},
647648
) == {"x": 1, "y": 2}
648649

649-
# duplicate dimensions
650-
with pytest.raises(ValueError):
651-
unified_dim_sizes([xr.Variable(("x", "x"), [[1]])])
650+
with pytest.raises(ValueError, match="broadcasting cannot handle"):
651+
with pytest.warns(UserWarning, match="Duplicate dimension names"):
652+
unified_dim_sizes([xr.Variable(("x", "x"), [[1]])])
652653

653654
# mismatched lengths
654655
with pytest.raises(ValueError):

xarray/tests/test_dataset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6007,6 +6007,8 @@ def test_dataset_number_math(self) -> None:
60076007
actual += 0
60086008
assert_identical(ds, actual)
60096009

6010+
# casting nan warns
6011+
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast")
60106012
def test_unary_ops(self) -> None:
60116013
ds = self.make_example_math_dataset()
60126014

xarray/tests/test_variable.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,8 @@ def test_from_sparse(self, Var):
29522952
import sparse
29532953

29542954
arr = np.diagflat([1, 2, 3])
2955-
sparr = sparse.COO(coords=[[0, 1, 2], [0, 1, 2]], data=[1, 2, 3])
2955+
coords = np.array([[0, 1, 2], [0, 1, 2]])
2956+
sparr = sparse.COO(coords=coords, data=[1, 2, 3], shape=(3, 3))
29562957
v = Variable(["x", "y"], sparr)
29572958

29582959
assert_identical(v.as_numpy(), Variable(["x", "y"], arr))

0 commit comments

Comments
 (0)