Skip to content

Commit d8c166b

Browse files
mathauseandersy005
andauthored
update pytest config and un-xfail some tests (#8246)
* update pytest config and un-xfail some tests * requires numbagg * requires dask * add reason * Update xarray/tests/test_variable.py * Update xarray/tests/test_units.py * Apply suggestions from code review * Update xarray/tests/test_backends.py --------- Co-authored-by: Anderson Banihirwe <[email protected]>
1 parent a5f666b commit d8c166b

8 files changed

+74
-58
lines changed

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ select = [
190190
known-first-party = ["xarray"]
191191

192192
[tool.pytest.ini_options]
193-
addopts = '--strict-markers'
193+
addopts = ["--strict-config", "--strict-markers"]
194+
log_cli_level = "INFO"
195+
minversion = "7"
194196
filterwarnings = [
195197
"ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
196198
]

xarray/tests/test_backends.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,6 @@ def multiple_indexing(indexers):
714714
]
715715
multiple_indexing(indexers5)
716716

717-
@pytest.mark.xfail(
718-
reason="zarr without dask handles negative steps in slices incorrectly",
719-
)
720717
def test_vectorized_indexing_negative_step(self) -> None:
721718
# use dask explicitly when present
722719
open_kwargs: dict[str, Any] | None
@@ -1842,8 +1839,8 @@ def test_unsorted_index_raises(self) -> None:
18421839
# dask first pulls items by block.
18431840
pass
18441841

1842+
@pytest.mark.skip(reason="caching behavior differs for dask")
18451843
def test_dataset_caching(self) -> None:
1846-
# caching behavior differs for dask
18471844
pass
18481845

18491846
def test_write_inconsistent_chunks(self) -> None:
@@ -2261,9 +2258,6 @@ def test_encoding_kwarg_fixed_width_string(self) -> None:
22612258
# not relevant for zarr, since we don't use EncodedStringCoder
22622259
pass
22632260

2264-
# TODO: someone who understand caching figure out whether caching
2265-
# makes sense for Zarr backend
2266-
@pytest.mark.xfail(reason="Zarr caching not implemented")
22672261
def test_dataset_caching(self) -> None:
22682262
super().test_dataset_caching()
22692263

@@ -2712,6 +2706,14 @@ def test_attributes(self, obj) -> None:
27122706
with pytest.raises(TypeError, match=r"Invalid attribute in Dataset.attrs."):
27132707
ds.to_zarr(store_target, **self.version_kwargs)
27142708

2709+
def test_vectorized_indexing_negative_step(self) -> None:
2710+
if not has_dask:
2711+
pytest.xfail(
2712+
reason="zarr without dask handles negative steps in slices incorrectly"
2713+
)
2714+
2715+
super().test_vectorized_indexing_negative_step()
2716+
27152717

27162718
@requires_zarr
27172719
class TestZarrDictStore(ZarrBase):
@@ -3378,8 +3380,8 @@ def roundtrip(
33783380
) as ds:
33793381
yield ds
33803382

3383+
@pytest.mark.skip(reason="caching behavior differs for dask")
33813384
def test_dataset_caching(self) -> None:
3382-
# caching behavior differs for dask
33833385
pass
33843386

33853387
def test_write_inconsistent_chunks(self) -> None:
@@ -3982,7 +3984,6 @@ def test_open_mfdataset_raise_on_bad_combine_args(self) -> None:
39823984
with pytest.raises(ValueError, match="`concat_dim` has no effect"):
39833985
open_mfdataset([tmp1, tmp2], concat_dim="x")
39843986

3985-
@pytest.mark.xfail(reason="mfdataset loses encoding currently.")
39863987
def test_encoding_mfdataset(self) -> None:
39873988
original = Dataset(
39883989
{
@@ -4195,7 +4196,6 @@ def test_dataarray_compute(self) -> None:
41954196
assert computed._in_memory
41964197
assert_allclose(actual, computed, decode_bytes=False)
41974198

4198-
@pytest.mark.xfail
41994199
def test_save_mfdataset_compute_false_roundtrip(self) -> None:
42004200
from dask.delayed import Delayed
42014201

@@ -5125,15 +5125,17 @@ def test_open_fsspec() -> None:
51255125
ds2 = open_dataset(url, engine="zarr")
51265126
xr.testing.assert_equal(ds0, ds2)
51275127

5128-
# multi dataset
5129-
url = "memory://out*.zarr"
5130-
ds2 = open_mfdataset(url, engine="zarr")
5131-
xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2)
5132-
5133-
# multi dataset with caching
5134-
url = "simplecache::memory://out*.zarr"
5135-
ds2 = open_mfdataset(url, engine="zarr")
5136-
xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2)
5128+
# open_mfdataset requires dask
5129+
if has_dask:
5130+
# multi dataset
5131+
url = "memory://out*.zarr"
5132+
ds2 = open_mfdataset(url, engine="zarr")
5133+
xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2)
5134+
5135+
# multi dataset with caching
5136+
url = "simplecache::memory://out*.zarr"
5137+
ds2 = open_mfdataset(url, engine="zarr")
5138+
xr.testing.assert_equal(xr.concat([ds, ds0], dim="time"), ds2)
51375139

51385140

51395141
@requires_h5netcdf

xarray/tests/test_cftimeindex.py

-1
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,6 @@ def test_to_datetimeindex_feb_29(calendar):
11351135

11361136

11371137
@requires_cftime
1138-
@pytest.mark.xfail(reason="https://github.com/pandas-dev/pandas/issues/24263")
11391138
def test_multiindex():
11401139
index = xr.cftime_range("2001-01-01", periods=100, calendar="360_day")
11411140
mindex = pd.MultiIndex.from_arrays([index])

xarray/tests/test_options.py

-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def test_concat_attr_retention(self) -> None:
165165
result = concat([ds1, ds2], dim="dim1")
166166
assert result.attrs == original_attrs
167167

168-
@pytest.mark.xfail
169168
def test_merge_attr_retention(self) -> None:
170169
da1 = create_test_dataarray_attrs(var="var1")
171170
da2 = create_test_dataarray_attrs(var="var2")

xarray/tests/test_rolling.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,7 @@ def test_ndrolling_construct(self, center, fill_value, dask) -> None:
766766
)
767767
assert_allclose(actual, expected)
768768

769-
@pytest.mark.xfail(
770-
reason="See https://github.com/pydata/xarray/pull/4369 or docstring"
771-
)
769+
@requires_dask
772770
@pytest.mark.filterwarnings("error")
773771
@pytest.mark.parametrize("ds", (2,), indirect=True)
774772
@pytest.mark.parametrize("name", ("mean", "max"))

xarray/tests/test_sparse.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ def test_variable_property(prop):
147147
],
148148
),
149149
True,
150-
marks=xfail(reason="Coercion to dense"),
151150
),
152151
param(
153152
do("conjugate"),
@@ -201,7 +200,6 @@ def test_variable_property(prop):
201200
param(
202201
do("reduce", func="sum", dim="x"),
203202
True,
204-
marks=xfail(reason="Coercion to dense"),
205203
),
206204
param(
207205
do("rolling_window", dim="x", window=2, window_dim="x_win"),
@@ -218,7 +216,7 @@ def test_variable_property(prop):
218216
param(
219217
do("var"), False, marks=xfail(reason="Missing implementation for np.nanvar")
220218
),
221-
param(do("to_dict"), False, marks=xfail(reason="Coercion to dense")),
219+
param(do("to_dict"), False),
222220
(do("where", cond=make_xrvar({"x": 10, "y": 5}) > 0.5), True),
223221
],
224222
ids=repr,
@@ -237,7 +235,14 @@ def test_variable_method(func, sparse_output):
237235
assert isinstance(ret_s.data, sparse.SparseArray)
238236
assert np.allclose(ret_s.data.todense(), ret_d.data, equal_nan=True)
239237
else:
240-
assert np.allclose(ret_s, ret_d, equal_nan=True)
238+
if func.meth != "to_dict":
239+
assert np.allclose(ret_s, ret_d)
240+
else:
241+
# pop the arrays from the dict
242+
arr_s, arr_d = ret_s.pop("data"), ret_d.pop("data")
243+
244+
assert np.allclose(arr_s, arr_d)
245+
assert ret_s == ret_d
241246

242247

243248
@pytest.mark.parametrize(

xarray/tests/test_units.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
assert_identical,
1919
requires_dask,
2020
requires_matplotlib,
21+
requires_numbagg,
2122
)
2223
from xarray.tests.test_plot import PlotTestCase
2324
from xarray.tests.test_variable import _PAD_XR_NP_ARGS
@@ -2548,7 +2549,6 @@ def test_univariate_ufunc(self, units, error, dtype):
25482549
assert_units_equal(expected, actual)
25492550
assert_identical(expected, actual)
25502551

2551-
@pytest.mark.xfail(reason="needs the type register system for __array_ufunc__")
25522552
@pytest.mark.parametrize(
25532553
"unit,error",
25542554
(
@@ -3849,23 +3849,21 @@ def test_computation(self, func, variant, dtype):
38493849
method("groupby", "x"),
38503850
method("groupby_bins", "y", bins=4),
38513851
method("coarsen", y=2),
3852-
pytest.param(
3853-
method("rolling", y=3),
3854-
marks=pytest.mark.xfail(
3855-
reason="numpy.lib.stride_tricks.as_strided converts to ndarray"
3856-
),
3857-
),
3858-
pytest.param(
3859-
method("rolling_exp", y=3),
3860-
marks=pytest.mark.xfail(
3861-
reason="numbagg functions are not supported by pint"
3862-
),
3863-
),
3852+
method("rolling", y=3),
3853+
pytest.param(method("rolling_exp", y=3), marks=requires_numbagg),
38643854
method("weighted", xr.DataArray(data=np.linspace(0, 1, 10), dims="y")),
38653855
),
38663856
ids=repr,
38673857
)
38683858
def test_computation_objects(self, func, variant, dtype):
3859+
if variant == "data":
3860+
if func.name == "rolling_exp":
3861+
pytest.xfail(reason="numbagg functions are not supported by pint")
3862+
elif func.name == "rolling":
3863+
pytest.xfail(
3864+
reason="numpy.lib.stride_tricks.as_strided converts to ndarray"
3865+
)
3866+
38693867
unit = unit_registry.m
38703868

38713869
variants = {

xarray/tests/test_variable.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -885,20 +885,10 @@ def test_getitem_error(self):
885885
"mode",
886886
[
887887
"mean",
888-
pytest.param(
889-
"median",
890-
marks=pytest.mark.xfail(reason="median is not implemented by Dask"),
891-
),
892-
pytest.param(
893-
"reflect", marks=pytest.mark.xfail(reason="dask.array.pad bug")
894-
),
888+
"median",
889+
"reflect",
895890
"edge",
896-
pytest.param(
897-
"linear_ramp",
898-
marks=pytest.mark.xfail(
899-
reason="pint bug: https://github.com/hgrecco/pint/issues/1026"
900-
),
901-
),
891+
"linear_ramp",
902892
"maximum",
903893
"minimum",
904894
"symmetric",
@@ -2345,12 +2335,35 @@ def test_dask_rolling(self, dim, window, center):
23452335
assert actual.shape == expected.shape
23462336
assert_equal(actual, expected)
23472337

2348-
@pytest.mark.xfail(
2349-
reason="https://github.com/pydata/xarray/issues/6209#issuecomment-1025116203"
2350-
)
23512338
def test_multiindex(self):
23522339
super().test_multiindex()
23532340

2341+
@pytest.mark.parametrize(
2342+
"mode",
2343+
[
2344+
"mean",
2345+
pytest.param(
2346+
"median",
2347+
marks=pytest.mark.xfail(reason="median is not implemented by Dask"),
2348+
),
2349+
pytest.param(
2350+
"reflect", marks=pytest.mark.xfail(reason="dask.array.pad bug")
2351+
),
2352+
"edge",
2353+
"linear_ramp",
2354+
"maximum",
2355+
"minimum",
2356+
"symmetric",
2357+
"wrap",
2358+
],
2359+
)
2360+
@pytest.mark.parametrize("xr_arg, np_arg", _PAD_XR_NP_ARGS)
2361+
@pytest.mark.filterwarnings(
2362+
r"ignore:dask.array.pad.+? converts integers to floats."
2363+
)
2364+
def test_pad(self, mode, xr_arg, np_arg):
2365+
super().test_pad(mode, xr_arg, np_arg)
2366+
23542367

23552368
@requires_sparse
23562369
class TestVariableWithSparse:

0 commit comments

Comments
 (0)