diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 56cd0649989..95ee14c0c8c 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -1253,7 +1253,7 @@ def check_dtype(var): if ( not np.issubdtype(var.dtype, np.number) and not np.issubdtype(var.dtype, np.datetime64) - and not np.issubdtype(var.dtype, np.bool) + and not np.issubdtype(var.dtype, np.bool_) and not coding.strings.is_unicode_dtype(var.dtype) and not var.dtype == object ): diff --git a/xarray/tests/test_accessor_dt.py b/xarray/tests/test_accessor_dt.py index 1a8a2732eeb..20a9283e32c 100644 --- a/xarray/tests/test_accessor_dt.py +++ b/xarray/tests/test_accessor_dt.py @@ -347,6 +347,7 @@ def test_field_access(data, field): @requires_cftime +@pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_cftime_strftime_access(data): """ compare cftime formatting against datetime formatting """ date_format = "%Y%m%d%H" diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 59ed8e690cc..5f8ba83c330 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -1921,33 +1921,36 @@ def test_to_zarr_append_compute_false_roundtrip(self): ds, ds_to_append, _ = create_append_test_data() ds, ds_to_append = ds.chunk(), ds_to_append.chunk() - with self.create_zarr_target() as store: - delayed_obj = self.save(ds, store, compute=False, mode="w") - assert isinstance(delayed_obj, Delayed) + with pytest.warns(SerializationWarning): + with self.create_zarr_target() as store: + delayed_obj = self.save(ds, store, compute=False, mode="w") + assert isinstance(delayed_obj, Delayed) + + with pytest.raises(AssertionError): + with self.open(store) as actual: + assert_identical(ds, actual) + + delayed_obj.compute() - with pytest.raises(AssertionError): with self.open(store) as actual: assert_identical(ds, actual) - delayed_obj.compute() + delayed_obj = self.save( + ds_to_append, store, compute=False, append_dim="time" + ) + assert isinstance(delayed_obj, Delayed) - with self.open(store) as actual: - assert_identical(ds, actual) + with pytest.raises(AssertionError): + with self.open(store) as actual: + assert_identical( + xr.concat([ds, ds_to_append], dim="time"), actual + ) - delayed_obj = self.save( - ds_to_append, store, compute=False, append_dim="time" - ) - assert isinstance(delayed_obj, Delayed) + delayed_obj.compute() - with pytest.raises(AssertionError): with self.open(store) as actual: assert_identical(xr.concat([ds, ds_to_append], dim="time"), actual) - delayed_obj.compute() - - with self.open(store) as actual: - assert_identical(xr.concat([ds, ds_to_append], dim="time"), actual) - def test_encoding_chunksizes(self): # regression test for GH2278 # see also test_encoding_chunksizes_unlimited @@ -3519,6 +3522,7 @@ def test_uamiv_format_mfread(self): ["example.uamiv", "example.uamiv"], engine="pseudonetcdf", concat_dim="TSTEP", + combine="nested", backend_kwargs={"format": "uamiv"}, ) diff --git a/xarray/tests/test_concat.py b/xarray/tests/test_concat.py index bd99181a947..cd51528dd4e 100644 --- a/xarray/tests/test_concat.py +++ b/xarray/tests/test_concat.py @@ -40,8 +40,7 @@ def test_concat_compat(): assert_equal(ds2.no_x_y, result.no_x_y.transpose()) for var in ["has_x", "no_x_y"]: - assert "y" not in result[var] - + assert "y" not in result[var].dims and "y" not in result[var].coords with raises_regex(ValueError, "coordinates in some datasets but not others"): concat([ds1, ds2], dim="q") with raises_regex(ValueError, "'q' is not present in all datasets"): diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index 8fb54c4ee84..4f7e3910f82 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -1344,6 +1344,7 @@ def test_normalize_token_with_backend(map_ds): map_ds.to_netcdf(tmp_file) read = xr.open_dataset(tmp_file) assert not dask.base.tokenize(map_ds) == dask.base.tokenize(read) + read.close() @pytest.mark.parametrize( diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index dfaf8fd4e28..ef3da5a3b94 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2035,7 +2035,7 @@ def test_stack_unstack(self): codes=[[], []], names=["x", "y"], ) - pd.util.testing.assert_index_equal(a, b) + pd.testing.assert_index_equal(a, b) actual = orig.stack(z=["x", "y"]).unstack("z").drop_vars(["x", "y"]) assert_identical(orig, actual) @@ -3488,7 +3488,7 @@ def test_from_series_sparse(self): def test_to_and_from_empty_series(self): # GH697 - expected = pd.Series([]) + expected = pd.Series([], dtype=np.float64) da = DataArray.from_series(expected) assert len(da) == 0 actual = da.to_series() diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index d2e8c6b7609..cd6bdd65f17 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -6031,7 +6031,7 @@ def test_integrate(dask): actual = da.integrate("x") # coordinate that contains x should be dropped. expected_x = xr.DataArray( - np.trapz(da, da["x"], axis=0), + np.trapz(da.compute(), da["x"], axis=0), dims=["y"], coords={k: v for k, v in da.coords.items() if "x" not in v.dims}, ) diff --git a/xarray/tests/test_duck_array_ops.py b/xarray/tests/test_duck_array_ops.py index f4f11473e48..157cd16cba6 100644 --- a/xarray/tests/test_duck_array_ops.py +++ b/xarray/tests/test_duck_array_ops.py @@ -279,6 +279,7 @@ def assert_dask_array(da, dask): @arm_xfail +@pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize("dask", [False, True] if has_dask else [False]) def test_datetime_mean(dask): # Note: only testing numpy, as dask is broken upstream diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index 77558e741be..e12da17afee 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -414,7 +414,8 @@ def test_groupby_drops_nans(): # reduction operation along a different dimension actual = grouped.mean("time") - expected = ds.mean("time").where(ds.id.notnull()) + with pytest.warns(RuntimeWarning): # mean of empty slice + expected = ds.mean("time").where(ds.id.notnull()) assert_identical(actual, expected) # NaN in non-dimensional coordinate diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 9ffbcd9c85e..c1549c62038 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1749,6 +1749,7 @@ def test_can_set_vmin_vmax(self): assert np.allclose(expected, clim) @pytest.mark.slow + @pytest.mark.filterwarnings("ignore") def test_can_set_norm(self): norm = mpl.colors.SymLogNorm(0.1) self.g.map_dataarray(xplt.imshow, "x", "y", norm=norm)