From 8da260870c7df58f3a42b72dcf404f5af2af690b Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 16:19:13 +0200 Subject: [PATCH 1/8] update pytest config and un-xfail some tests --- pyproject.toml | 4 ++- xarray/tests/test_backends.py | 36 ++++++++++++++----------- xarray/tests/test_cftimeindex.py | 1 - xarray/tests/test_options.py | 1 - xarray/tests/test_rolling.py | 3 --- xarray/tests/test_sparse.py | 13 ++++++--- xarray/tests/test_units.py | 23 +++++++--------- xarray/tests/test_variable.py | 46 +++++++++++++++++++++----------- 8 files changed, 72 insertions(+), 55 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 25263928b20..4e60590d994 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -155,7 +155,9 @@ select = [ known-first-party = ["xarray"] [tool.pytest.ini_options] -addopts = '--strict-markers' +addopts = ["--strict-config", "--strict-markers"] +log_cli_level = "INFO" +minversion = "7" filterwarnings = [ "ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning", ] diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 5bd517098f1..cf75993e44a 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -714,9 +714,6 @@ def multiple_indexing(indexers): ] multiple_indexing(indexers5) - @pytest.mark.xfail( - reason="zarr without dask handles negative steps in slices incorrectly", - ) def test_vectorized_indexing_negative_step(self) -> None: # use dask explicitly when present open_kwargs: dict[str, Any] | None @@ -1842,6 +1839,7 @@ def test_unsorted_index_raises(self) -> None: # dask first pulls items by block. pass + @pytest.mark.skip() def test_dataset_caching(self) -> None: # caching behavior differs for dask pass @@ -2261,9 +2259,6 @@ def test_encoding_kwarg_fixed_width_string(self) -> None: # not relevant for zarr, since we don't use EncodedStringCoder pass - # TODO: someone who understand caching figure out whether caching - # makes sense for Zarr backend - @pytest.mark.xfail(reason="Zarr caching not implemented") def test_dataset_caching(self) -> None: super().test_dataset_caching() @@ -2712,6 +2707,14 @@ def test_attributes(self, obj) -> None: with pytest.raises(TypeError, match=r"Invalid attribute in Dataset.attrs."): ds.to_zarr(store_target, **self.version_kwargs) + def test_vectorized_indexing_negative_step(self) -> None: + if not has_dask: + pytest.xfail( + reason="zarr without dask handles negative steps in slices incorrectly" + ) + + super().test_vectorized_indexing_negative_step() + @requires_zarr class TestZarrDictStore(ZarrBase): @@ -3378,6 +3381,7 @@ def roundtrip( ) as ds: yield ds + @pytest.mark.skip() def test_dataset_caching(self) -> None: # caching behavior differs for dask pass @@ -3455,6 +3459,7 @@ def skip_if_not_engine(engine): pytest.importorskip(engine) +@pytest.mark.skip("fails") @requires_dask @pytest.mark.filterwarnings("ignore:use make_scale(name) instead") def test_open_mfdataset_manyfiles( @@ -3982,7 +3987,6 @@ def test_open_mfdataset_raise_on_bad_combine_args(self) -> None: with pytest.raises(ValueError, match="`concat_dim` has no effect"): open_mfdataset([tmp1, tmp2], concat_dim="x") - @pytest.mark.xfail(reason="mfdataset loses encoding currently.") def test_encoding_mfdataset(self) -> None: original = Dataset( { @@ -4195,7 +4199,6 @@ def test_dataarray_compute(self) -> None: assert computed._in_memory assert_allclose(actual, computed, decode_bytes=False) - @pytest.mark.xfail def test_save_mfdataset_compute_false_roundtrip(self) -> None: from dask.delayed import Delayed @@ -5125,15 +5128,16 @@ def test_open_fsspec() -> None: ds2 = open_dataset(url, engine="zarr") xr.testing.assert_equal(ds0, ds2) - # multi dataset - url = "memory://out*.zarr" - ds2 = open_mfdataset(url, engine="zarr") - xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2) + if has_dask: + # multi dataset + url = "memory://out*.zarr" + ds2 = open_mfdataset(url, engine="zarr") + xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2) - # multi dataset with caching - url = "simplecache::memory://out*.zarr" - ds2 = open_mfdataset(url, engine="zarr") - xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2) + # multi dataset with caching + url = "simplecache::memory://out*.zarr" + ds2 = open_mfdataset(url, engine="zarr") + xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2) @requires_h5netcdf diff --git a/xarray/tests/test_cftimeindex.py b/xarray/tests/test_cftimeindex.py index f58a6490632..1a1df6b81fe 100644 --- a/xarray/tests/test_cftimeindex.py +++ b/xarray/tests/test_cftimeindex.py @@ -1135,7 +1135,6 @@ def test_to_datetimeindex_feb_29(calendar): @requires_cftime -@pytest.mark.xfail(reason="https://github.com/pandas-dev/pandas/issues/24263") def test_multiindex(): index = xr.cftime_range("2001-01-01", periods=100, calendar="360_day") mindex = pd.MultiIndex.from_arrays([index]) diff --git a/xarray/tests/test_options.py b/xarray/tests/test_options.py index 3cecf1b52ec..8ad1cbe11be 100644 --- a/xarray/tests/test_options.py +++ b/xarray/tests/test_options.py @@ -165,7 +165,6 @@ def test_concat_attr_retention(self) -> None: result = concat([ds1, ds2], dim="dim1") assert result.attrs == original_attrs - @pytest.mark.xfail def test_merge_attr_retention(self) -> None: da1 = create_test_dataarray_attrs(var="var1") da2 = create_test_dataarray_attrs(var="var2") diff --git a/xarray/tests/test_rolling.py b/xarray/tests/test_rolling.py index 72d1b9071dd..af8ca48e31d 100644 --- a/xarray/tests/test_rolling.py +++ b/xarray/tests/test_rolling.py @@ -766,9 +766,6 @@ def test_ndrolling_construct(self, center, fill_value, dask) -> None: ) assert_allclose(actual, expected) - @pytest.mark.xfail( - reason="See https://github.com/pydata/xarray/pull/4369 or docstring" - ) @pytest.mark.filterwarnings("error") @pytest.mark.parametrize("ds", (2,), indirect=True) @pytest.mark.parametrize("name", ("mean", "max")) diff --git a/xarray/tests/test_sparse.py b/xarray/tests/test_sparse.py index f64ce9338d7..489836b70fd 100644 --- a/xarray/tests/test_sparse.py +++ b/xarray/tests/test_sparse.py @@ -147,7 +147,6 @@ def test_variable_property(prop): ], ), True, - marks=xfail(reason="Coercion to dense"), ), param( do("conjugate"), @@ -201,7 +200,6 @@ def test_variable_property(prop): param( do("reduce", func="sum", dim="x"), True, - marks=xfail(reason="Coercion to dense"), ), param( do("rolling_window", dim="x", window=2, window_dim="x_win"), @@ -218,7 +216,7 @@ def test_variable_property(prop): param( do("var"), False, marks=xfail(reason="Missing implementation for np.nanvar") ), - param(do("to_dict"), False, marks=xfail(reason="Coercion to dense")), + param(do("to_dict"), False), (do("where", cond=make_xrvar({"x": 10, "y": 5}) > 0.5), True), ], ids=repr, @@ -237,7 +235,14 @@ def test_variable_method(func, sparse_output): assert isinstance(ret_s.data, sparse.SparseArray) assert np.allclose(ret_s.data.todense(), ret_d.data, equal_nan=True) else: - assert np.allclose(ret_s, ret_d, equal_nan=True) + if func.meth != "to_dict": + assert np.allclose(ret_s, ret_d) + else: + # pop the arrays from the dict + arr_s, arr_d = ret_s.pop("data"), ret_d.pop("data") + + assert np.allclose(arr_s, arr_d) + assert ret_s == ret_d @pytest.mark.parametrize( diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index addd7587544..bed88c574c0 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -2548,7 +2548,6 @@ def test_univariate_ufunc(self, units, error, dtype): assert_units_equal(expected, actual) assert_identical(expected, actual) - @pytest.mark.xfail(reason="needs the type register system for __array_ufunc__") @pytest.mark.parametrize( "unit,error", ( @@ -3849,23 +3848,21 @@ def test_computation(self, func, variant, dtype): method("groupby", "x"), method("groupby_bins", "y", bins=4), method("coarsen", y=2), - pytest.param( - method("rolling", y=3), - marks=pytest.mark.xfail( - reason="numpy.lib.stride_tricks.as_strided converts to ndarray" - ), - ), - pytest.param( - method("rolling_exp", y=3), - marks=pytest.mark.xfail( - reason="numbagg functions are not supported by pint" - ), - ), + method("rolling", y=3), + method("rolling_exp", y=3), method("weighted", xr.DataArray(data=np.linspace(0, 1, 10), dims="y")), ), ids=repr, ) def test_computation_objects(self, func, variant, dtype): + if variant == "data": + if func.name == "rolling_exp": + pytest.xfail(reason="numbagg functions are not supported by pint") + elif func.name == "rolling": + pytest.xfail( + reason="numpy.lib.stride_tricks.as_strided converts to ndarray" + ) + unit = unit_registry.m variants = { diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index 4fcd5f98d8f..8e143a7d86f 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -885,20 +885,10 @@ def test_getitem_error(self): "mode", [ "mean", - pytest.param( - "median", - marks=pytest.mark.xfail(reason="median is not implemented by Dask"), - ), - pytest.param( - "reflect", marks=pytest.mark.xfail(reason="dask.array.pad bug") - ), + "median", + "reflect", "edge", - pytest.param( - "linear_ramp", - marks=pytest.mark.xfail( - reason="pint bug: https://github.com/hgrecco/pint/issues/1026" - ), - ), + "linear_ramp", "maximum", "minimum", "symmetric", @@ -2345,12 +2335,36 @@ def test_dask_rolling(self, dim, window, center): assert actual.shape == expected.shape assert_equal(actual, expected) - @pytest.mark.xfail( - reason="https://github.com/pydata/xarray/issues/6209#issuecomment-1025116203" - ) def test_multiindex(self): super().test_multiindex() + @pytest.mark.skip + @pytest.mark.parametrize( + "mode", + [ + "mean", + pytest.param( + "median", + marks=pytest.mark.xfail(reason="median is not implemented by Dask"), + ), + pytest.param( + "reflect", marks=pytest.mark.xfail(reason="dask.array.pad bug") + ), + "edge", + "linear_ramp", + "maximum", + "minimum", + "symmetric", + "wrap", + ], + ) + @pytest.mark.parametrize("xr_arg, np_arg", _PAD_XR_NP_ARGS) + @pytest.mark.filterwarnings( + r"ignore:dask.array.pad.+? converts integers to floats." + ) + def test_pad(self, mode, xr_arg, np_arg): + super().test_pad(mode, xr_arg, np_arg) + @requires_sparse class TestVariableWithSparse: From f158afdc88f9d7a5015529b70f871d7689ebd867 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 16:52:56 +0200 Subject: [PATCH 2/8] requires numbagg --- xarray/tests/test_units.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index bed88c574c0..ee67f5f5c82 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -18,6 +18,7 @@ assert_identical, requires_dask, requires_matplotlib, + requires_numbagg, ) from xarray.tests.test_plot import PlotTestCase from xarray.tests.test_variable import _PAD_XR_NP_ARGS @@ -3849,7 +3850,7 @@ def test_computation(self, func, variant, dtype): method("groupby_bins", "y", bins=4), method("coarsen", y=2), method("rolling", y=3), - method("rolling_exp", y=3), + pytest.param(method("rolling_exp", y=3), mark=requires_numbagg), method("weighted", xr.DataArray(data=np.linspace(0, 1, 10), dims="y")), ), ids=repr, From 09801b55ed32298271cbcde0ae2996299a563871 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 16:53:24 +0200 Subject: [PATCH 3/8] requires dask --- xarray/tests/test_rolling.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/tests/test_rolling.py b/xarray/tests/test_rolling.py index af8ca48e31d..2dc8ae24438 100644 --- a/xarray/tests/test_rolling.py +++ b/xarray/tests/test_rolling.py @@ -766,6 +766,7 @@ def test_ndrolling_construct(self, center, fill_value, dask) -> None: ) assert_allclose(actual, expected) + @requires_dask @pytest.mark.filterwarnings("error") @pytest.mark.parametrize("ds", (2,), indirect=True) @pytest.mark.parametrize("name", ("mean", "max")) From 4be9ecb0aab26472c8e747453a908236ac044588 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 16:53:42 +0200 Subject: [PATCH 4/8] add reason --- xarray/tests/test_backends.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index cf75993e44a..0821e38bbdb 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -1839,9 +1839,8 @@ def test_unsorted_index_raises(self) -> None: # dask first pulls items by block. pass - @pytest.mark.skip() + @pytest.mark.skip(reason="caching behavior differs for dask") def test_dataset_caching(self) -> None: - # caching behavior differs for dask pass def test_write_inconsistent_chunks(self) -> None: @@ -3381,9 +3380,8 @@ def roundtrip( ) as ds: yield ds - @pytest.mark.skip() + @pytest.mark.skip(reason="caching behavior differs for dask") def test_dataset_caching(self) -> None: - # caching behavior differs for dask pass def test_write_inconsistent_chunks(self) -> None: From 88155cd2ef81f38a4d38112dee51b0388a47c00a Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 16:54:18 +0200 Subject: [PATCH 5/8] Update xarray/tests/test_variable.py --- xarray/tests/test_variable.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index 8e143a7d86f..f162b1c7d0a 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -2338,7 +2338,6 @@ def test_dask_rolling(self, dim, window, center): def test_multiindex(self): super().test_multiindex() - @pytest.mark.skip @pytest.mark.parametrize( "mode", [ From 840a786516c34022ac93b3e8e5cc5867c9530c1c Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 17:01:08 +0200 Subject: [PATCH 6/8] Update xarray/tests/test_units.py --- xarray/tests/test_units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index ee67f5f5c82..d89a74e4fba 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -3850,7 +3850,7 @@ def test_computation(self, func, variant, dtype): method("groupby_bins", "y", bins=4), method("coarsen", y=2), method("rolling", y=3), - pytest.param(method("rolling_exp", y=3), mark=requires_numbagg), + pytest.param(method("rolling_exp", y=3), marks=requires_numbagg), method("weighted", xr.DataArray(data=np.linspace(0, 1, 10), dims="y")), ), ids=repr, From e8d427c0f79bd4bc2ac7e1e880a0e922be5b6e65 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 17:04:57 +0200 Subject: [PATCH 7/8] Apply suggestions from code review --- xarray/tests/test_backends.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 0821e38bbdb..e3c0e930c51 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -3457,7 +3457,6 @@ def skip_if_not_engine(engine): pytest.importorskip(engine) -@pytest.mark.skip("fails") @requires_dask @pytest.mark.filterwarnings("ignore:use make_scale(name) instead") def test_open_mfdataset_manyfiles( From 91a80dacd6fbcb8af616184b4b83d87682da0738 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 28 Sep 2023 17:11:04 +0200 Subject: [PATCH 8/8] Update xarray/tests/test_backends.py --- xarray/tests/test_backends.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index e3c0e930c51..0cbf3af3664 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -5125,6 +5125,7 @@ def test_open_fsspec() -> None: ds2 = open_dataset(url, engine="zarr") xr.testing.assert_equal(ds0, ds2) + # open_mfdataset requires dask if has_dask: # multi dataset url = "memory://out*.zarr"