Skip to content

Commit 0dedcb0

Browse files
authored
move da and ds fixtures to conftest.py (#6730)
* rename and move da and ds fixtures * rename to dataarray & dataset * fix mypy * rename back to da and ds
1 parent 6771b66 commit 0dedcb0

File tree

8 files changed

+77
-84
lines changed

8 files changed

+77
-84
lines changed

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ ignore =
152152
E501 # line too long - let black worry about that
153153
E731 # do not assign a lambda expression, use a def
154154
W503 # line break before binary operator
155-
per-file-ignores =
156-
xarray/tests/*.py:F401,F811
157155
exclude=
158156
.eggs
159157
doc

xarray/tests/conftest.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,80 @@
1+
import numpy as np
2+
import pandas as pd
13
import pytest
24

3-
from . import requires_dask
5+
from xarray import DataArray, Dataset
6+
7+
from . import create_test_data, requires_dask
48

59

610
@pytest.fixture(params=["numpy", pytest.param("dask", marks=requires_dask)])
711
def backend(request):
812
return request.param
13+
14+
15+
@pytest.fixture(params=[1])
16+
def ds(request, backend):
17+
if request.param == 1:
18+
ds = Dataset(
19+
dict(
20+
z1=(["y", "x"], np.random.randn(2, 8)),
21+
z2=(["time", "y"], np.random.randn(10, 2)),
22+
),
23+
dict(
24+
x=("x", np.linspace(0, 1.0, 8)),
25+
time=("time", np.linspace(0, 1.0, 10)),
26+
c=("y", ["a", "b"]),
27+
y=range(2),
28+
),
29+
)
30+
elif request.param == 2:
31+
ds = Dataset(
32+
dict(
33+
z1=(["time", "y"], np.random.randn(10, 2)),
34+
z2=(["time"], np.random.randn(10)),
35+
z3=(["x", "time"], np.random.randn(8, 10)),
36+
),
37+
dict(
38+
x=("x", np.linspace(0, 1.0, 8)),
39+
time=("time", np.linspace(0, 1.0, 10)),
40+
c=("y", ["a", "b"]),
41+
y=range(2),
42+
),
43+
)
44+
elif request.param == 3:
45+
ds = create_test_data()
46+
else:
47+
raise ValueError
48+
49+
if backend == "dask":
50+
return ds.chunk()
51+
52+
return ds
53+
54+
55+
@pytest.fixture(params=[1])
56+
def da(request, backend):
57+
if request.param == 1:
58+
times = pd.date_range("2000-01-01", freq="1D", periods=21)
59+
da = DataArray(
60+
np.random.random((3, 21, 4)),
61+
dims=("a", "time", "x"),
62+
coords=dict(time=times),
63+
)
64+
65+
if request.param == 2:
66+
da = DataArray([0, np.nan, 1, 2, np.nan, 3, 4, 5, np.nan, 6, 7], dims="time")
67+
68+
if request.param == "repeating_ints":
69+
da = DataArray(
70+
np.tile(np.arange(12), 5).reshape(5, 4, 3),
71+
coords={"x": list("abc"), "y": list("defg")},
72+
dims=list("zyx"),
73+
)
74+
75+
if backend == "dask":
76+
return da.chunk()
77+
elif backend == "numpy":
78+
return da
79+
else:
80+
raise ValueError

xarray/tests/test_coarsen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
raise_if_dask_computes,
1616
requires_cftime,
1717
)
18-
from .test_dataarray import da
19-
from .test_dataset import ds
2018

2119

2220
def test_coarsen_absent_dims_error(ds: Dataset) -> None:

xarray/tests/test_computation.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@
2424
unified_dim_sizes,
2525
)
2626
from xarray.core.pycompat import dask_version
27-
from xarray.core.types import T_Xarray
28-
29-
from . import (
30-
has_cftime,
31-
has_dask,
32-
raise_if_dask_computes,
33-
requires_cftime,
34-
requires_dask,
35-
)
27+
28+
from . import has_dask, raise_if_dask_computes, requires_cftime, requires_dask
3629

3730

3831
def assert_identical(a, b):

xarray/tests/test_dataarray.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5859,34 +5859,6 @@ def test_idxminmax_dask(self, op, ndim) -> None:
58595859
assert_equal(getattr(ar0_dsk, op)(dim="x"), getattr(ar0_raw, op)(dim="x"))
58605860

58615861

5862-
@pytest.fixture(params=[1])
5863-
def da(request, backend):
5864-
if request.param == 1:
5865-
times = pd.date_range("2000-01-01", freq="1D", periods=21)
5866-
da = DataArray(
5867-
np.random.random((3, 21, 4)),
5868-
dims=("a", "time", "x"),
5869-
coords=dict(time=times),
5870-
)
5871-
5872-
if request.param == 2:
5873-
da = DataArray([0, np.nan, 1, 2, np.nan, 3, 4, 5, np.nan, 6, 7], dims="time")
5874-
5875-
if request.param == "repeating_ints":
5876-
da = DataArray(
5877-
np.tile(np.arange(12), 5).reshape(5, 4, 3),
5878-
coords={"x": list("abc"), "y": list("defg")},
5879-
dims=list("zyx"),
5880-
)
5881-
5882-
if backend == "dask":
5883-
return da.chunk()
5884-
elif backend == "numpy":
5885-
return da
5886-
else:
5887-
raise ValueError
5888-
5889-
58905862
@pytest.mark.parametrize("da", ("repeating_ints",), indirect=True)
58915863
def test_isin(da) -> None:
58925864
expected = DataArray(

xarray/tests/test_dataset.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6151,46 +6151,6 @@ def test_dir_unicode(ds) -> None:
61516151
assert "unicode" in result
61526152

61536153

6154-
@pytest.fixture(params=[1])
6155-
def ds(request, backend):
6156-
if request.param == 1:
6157-
ds = Dataset(
6158-
dict(
6159-
z1=(["y", "x"], np.random.randn(2, 8)),
6160-
z2=(["time", "y"], np.random.randn(10, 2)),
6161-
),
6162-
dict(
6163-
x=("x", np.linspace(0, 1.0, 8)),
6164-
time=("time", np.linspace(0, 1.0, 10)),
6165-
c=("y", ["a", "b"]),
6166-
y=range(2),
6167-
),
6168-
)
6169-
elif request.param == 2:
6170-
ds = Dataset(
6171-
dict(
6172-
z1=(["time", "y"], np.random.randn(10, 2)),
6173-
z2=(["time"], np.random.randn(10)),
6174-
z3=(["x", "time"], np.random.randn(8, 10)),
6175-
),
6176-
dict(
6177-
x=("x", np.linspace(0, 1.0, 8)),
6178-
time=("time", np.linspace(0, 1.0, 10)),
6179-
c=("y", ["a", "b"]),
6180-
y=range(2),
6181-
),
6182-
)
6183-
elif request.param == 3:
6184-
ds = create_test_data()
6185-
else:
6186-
raise ValueError
6187-
6188-
if backend == "dask":
6189-
return ds.chunk()
6190-
6191-
return ds
6192-
6193-
61946154
@pytest.mark.parametrize(
61956155
"funcname, argument",
61966156
[

xarray/tests/test_indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from xarray.core.variable import IndexVariable, Variable
1919

20-
from . import assert_equal, assert_identical
20+
from . import assert_identical
2121

2222

2323
def test_asarray_tuplesafe() -> None:

xarray/tests/test_ufuncs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from . import assert_array_equal
99
from . import assert_identical as assert_identical_
10-
from . import assert_no_warnings, mock
10+
from . import mock
1111

1212

1313
def assert_identical(a, b):

0 commit comments

Comments
 (0)