diff --git a/xarray/tests/test_array_api.py b/xarray/tests/test_array_api.py index 47e38013662..c273260d7dd 100644 --- a/xarray/tests/test_array_api.py +++ b/xarray/tests/test_array_api.py @@ -51,6 +51,8 @@ def test_aggregation_skipna(arrays) -> None: assert_equal(actual, expected) +# casting nan warns +@pytest.mark.filterwarnings("ignore:invalid value encountered in cast") def test_astype(arrays) -> None: np_arr, xp_arr = arrays expected = np_arr.astype(np.int64) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index b3ded709fc0..5f693e7a990 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -4185,7 +4185,7 @@ def test_phony_dims_warning(self) -> None: fx.create_dataset(k, data=v) with pytest.warns(UserWarning, match="The 'phony_dims' kwarg"): with xr.open_dataset(tmp_file, engine="h5netcdf", group="bar") as ds: - assert ds.dims == { + assert ds.sizes == { "phony_dim_0": 5, "phony_dim_1": 5, "phony_dim_2": 5, @@ -4300,7 +4300,8 @@ def test_open_fileobj(self) -> None: # `raises_regex`?). Ref https://github.com/pydata/xarray/pull/5191 with open(tmp_file, "rb") as f: f.seek(8) - open_dataset(f) + with open_dataset(f): # ensure file gets closed + pass @requires_h5netcdf @@ -6587,11 +6588,11 @@ def test_h5netcdf_storage_options() -> None: ds2.to_netcdf(f2, engine="h5netcdf") files = [f"file://{f}" for f in [f1, f2]] - ds = xr.open_mfdataset( + with xr.open_mfdataset( files, engine="h5netcdf", concat_dim="time", combine="nested", storage_options={"skip_instance_cache": False}, - ) - assert_identical(xr.concat([ds1, ds2], dim="time"), ds) + ) as ds: + assert_identical(xr.concat([ds1, ds2], dim="time"), ds) diff --git a/xarray/tests/test_computation.py b/xarray/tests/test_computation.py index 1d80d874df0..8ca9d2bbbb5 100644 --- a/xarray/tests/test_computation.py +++ b/xarray/tests/test_computation.py @@ -634,6 +634,7 @@ def test_apply_groupby_add() -> None: add(data_array.groupby("y"), data_array.groupby("x")) +@pytest.mark.filterwarnings("ignore:Duplicate dimension names present") def test_unified_dim_sizes() -> None: assert unified_dim_sizes([xr.Variable((), 0)]) == {} assert unified_dim_sizes([xr.Variable("x", [1]), xr.Variable("x", [1])]) == {"x": 1} @@ -646,9 +647,9 @@ def test_unified_dim_sizes() -> None: exclude_dims={"z"}, ) == {"x": 1, "y": 2} - # duplicate dimensions - with pytest.raises(ValueError): - unified_dim_sizes([xr.Variable(("x", "x"), [[1]])]) + with pytest.raises(ValueError, match="broadcasting cannot handle"): + with pytest.warns(UserWarning, match="Duplicate dimension names"): + unified_dim_sizes([xr.Variable(("x", "x"), [[1]])]) # mismatched lengths with pytest.raises(ValueError): diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 0ab162cb214..bdae9daf758 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -6007,6 +6007,8 @@ def test_dataset_number_math(self) -> None: actual += 0 assert_identical(ds, actual) + # casting nan warns + @pytest.mark.filterwarnings("ignore:invalid value encountered in cast") def test_unary_ops(self) -> None: ds = self.make_example_math_dataset() diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index b1d5a09efcf..388f51bc568 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -2952,7 +2952,8 @@ def test_from_sparse(self, Var): import sparse arr = np.diagflat([1, 2, 3]) - sparr = sparse.COO(coords=[[0, 1, 2], [0, 1, 2]], data=[1, 2, 3]) + coords = np.array([[0, 1, 2], [0, 1, 2]]) + sparr = sparse.COO(coords=coords, data=[1, 2, 3], shape=(3, 3)) v = Variable(["x", "y"], sparr) assert_identical(v.as_numpy(), Variable(["x", "y"], arr))