diff --git a/setup.cfg b/setup.cfg index f5dd4dde810..af7d47c2b79 100644 --- a/setup.cfg +++ b/setup.cfg @@ -152,8 +152,6 @@ ignore = E501 # line too long - let black worry about that E731 # do not assign a lambda expression, use a def W503 # line break before binary operator -per-file-ignores = - xarray/tests/*.py:F401,F811 exclude= .eggs doc diff --git a/xarray/tests/conftest.py b/xarray/tests/conftest.py index 7988b4a7b19..658c349cd74 100644 --- a/xarray/tests/conftest.py +++ b/xarray/tests/conftest.py @@ -1,8 +1,80 @@ +import numpy as np +import pandas as pd import pytest -from . import requires_dask +from xarray import DataArray, Dataset + +from . import create_test_data, requires_dask @pytest.fixture(params=["numpy", pytest.param("dask", marks=requires_dask)]) def backend(request): return request.param + + +@pytest.fixture(params=[1]) +def ds(request, backend): + if request.param == 1: + ds = Dataset( + dict( + z1=(["y", "x"], np.random.randn(2, 8)), + z2=(["time", "y"], np.random.randn(10, 2)), + ), + dict( + x=("x", np.linspace(0, 1.0, 8)), + time=("time", np.linspace(0, 1.0, 10)), + c=("y", ["a", "b"]), + y=range(2), + ), + ) + elif request.param == 2: + ds = Dataset( + dict( + z1=(["time", "y"], np.random.randn(10, 2)), + z2=(["time"], np.random.randn(10)), + z3=(["x", "time"], np.random.randn(8, 10)), + ), + dict( + x=("x", np.linspace(0, 1.0, 8)), + time=("time", np.linspace(0, 1.0, 10)), + c=("y", ["a", "b"]), + y=range(2), + ), + ) + elif request.param == 3: + ds = create_test_data() + else: + raise ValueError + + if backend == "dask": + return ds.chunk() + + return ds + + +@pytest.fixture(params=[1]) +def da(request, backend): + if request.param == 1: + times = pd.date_range("2000-01-01", freq="1D", periods=21) + da = DataArray( + np.random.random((3, 21, 4)), + dims=("a", "time", "x"), + coords=dict(time=times), + ) + + if request.param == 2: + da = DataArray([0, np.nan, 1, 2, np.nan, 3, 4, 5, np.nan, 6, 7], dims="time") + + if request.param == "repeating_ints": + da = DataArray( + np.tile(np.arange(12), 5).reshape(5, 4, 3), + coords={"x": list("abc"), "y": list("defg")}, + dims=list("zyx"), + ) + + if backend == "dask": + return da.chunk() + elif backend == "numpy": + return da + else: + raise ValueError diff --git a/xarray/tests/test_coarsen.py b/xarray/tests/test_coarsen.py index 197d2db1f60..d44499856c6 100644 --- a/xarray/tests/test_coarsen.py +++ b/xarray/tests/test_coarsen.py @@ -15,8 +15,6 @@ raise_if_dask_computes, requires_cftime, ) -from .test_dataarray import da -from .test_dataset import ds def test_coarsen_absent_dims_error(ds: Dataset) -> None: diff --git a/xarray/tests/test_computation.py b/xarray/tests/test_computation.py index 1eaa772206e..cc40bfb0265 100644 --- a/xarray/tests/test_computation.py +++ b/xarray/tests/test_computation.py @@ -24,15 +24,8 @@ unified_dim_sizes, ) from xarray.core.pycompat import dask_version -from xarray.core.types import T_Xarray - -from . import ( - has_cftime, - has_dask, - raise_if_dask_computes, - requires_cftime, - requires_dask, -) + +from . import has_dask, raise_if_dask_computes, requires_cftime, requires_dask def assert_identical(a, b): diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index e259353902c..fecc06180a6 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -5859,34 +5859,6 @@ def test_idxminmax_dask(self, op, ndim) -> None: assert_equal(getattr(ar0_dsk, op)(dim="x"), getattr(ar0_raw, op)(dim="x")) -@pytest.fixture(params=[1]) -def da(request, backend): - if request.param == 1: - times = pd.date_range("2000-01-01", freq="1D", periods=21) - da = DataArray( - np.random.random((3, 21, 4)), - dims=("a", "time", "x"), - coords=dict(time=times), - ) - - if request.param == 2: - da = DataArray([0, np.nan, 1, 2, np.nan, 3, 4, 5, np.nan, 6, 7], dims="time") - - if request.param == "repeating_ints": - da = DataArray( - np.tile(np.arange(12), 5).reshape(5, 4, 3), - coords={"x": list("abc"), "y": list("defg")}, - dims=list("zyx"), - ) - - if backend == "dask": - return da.chunk() - elif backend == "numpy": - return da - else: - raise ValueError - - @pytest.mark.parametrize("da", ("repeating_ints",), indirect=True) def test_isin(da) -> None: expected = DataArray( diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index bc5bf1c0f1c..b79dcbefc57 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -6151,46 +6151,6 @@ def test_dir_unicode(ds) -> None: assert "unicode" in result -@pytest.fixture(params=[1]) -def ds(request, backend): - if request.param == 1: - ds = Dataset( - dict( - z1=(["y", "x"], np.random.randn(2, 8)), - z2=(["time", "y"], np.random.randn(10, 2)), - ), - dict( - x=("x", np.linspace(0, 1.0, 8)), - time=("time", np.linspace(0, 1.0, 10)), - c=("y", ["a", "b"]), - y=range(2), - ), - ) - elif request.param == 2: - ds = Dataset( - dict( - z1=(["time", "y"], np.random.randn(10, 2)), - z2=(["time"], np.random.randn(10)), - z3=(["x", "time"], np.random.randn(8, 10)), - ), - dict( - x=("x", np.linspace(0, 1.0, 8)), - time=("time", np.linspace(0, 1.0, 10)), - c=("y", ["a", "b"]), - y=range(2), - ), - ) - elif request.param == 3: - ds = create_test_data() - else: - raise ValueError - - if backend == "dask": - return ds.chunk() - - return ds - - @pytest.mark.parametrize( "funcname, argument", [ diff --git a/xarray/tests/test_indexes.py b/xarray/tests/test_indexes.py index 26a807922e7..302a68ab552 100644 --- a/xarray/tests/test_indexes.py +++ b/xarray/tests/test_indexes.py @@ -17,7 +17,7 @@ ) from xarray.core.variable import IndexVariable, Variable -from . import assert_equal, assert_identical +from . import assert_identical def test_asarray_tuplesafe() -> None: diff --git a/xarray/tests/test_ufuncs.py b/xarray/tests/test_ufuncs.py index 29b8fa6a895..d730746bd60 100644 --- a/xarray/tests/test_ufuncs.py +++ b/xarray/tests/test_ufuncs.py @@ -7,7 +7,7 @@ from . import assert_array_equal from . import assert_identical as assert_identical_ -from . import assert_no_warnings, mock +from . import mock def assert_identical(a, b):