Skip to content

Commit a562c57

Browse files
authored
Minor test cleanup (#45)
1 parent f8c3a89 commit a562c57

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

cf_xarray/tests/datasets.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@
7070
1e-3, attrs=dict(standard_name="specific_humidity detection_minimum", units="g/g"),
7171
)
7272
anc
73+
74+
multiple = xr.Dataset()
75+
multiple.coords["x1"] = ("x1", range(30), {"axis": "X"})
76+
multiple.coords["y1"] = ("y1", range(20), {"axis": "Y"})
77+
multiple.coords["x2"] = ("x2", range(10), {"axis": "X"})
78+
multiple.coords["y2"] = ("y2", range(5), {"axis": "Y"})
79+
80+
multiple["v1"] = (("x1", "y1"), np.ones((30, 20)) * 15)
81+
multiple["v2"] = (("x2", "y2"), np.ones((10, 5)) * 15)

cf_xarray/tests/test_accessor.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import matplotlib as mpl
22
import matplotlib.pyplot as plt
3-
import numpy as np
43
import pytest
54
import xarray as xr
65
from xarray.testing import assert_identical
76

87
import cf_xarray # noqa
98

109
from . import raise_if_dask_computes
11-
from .datasets import airds, anc, ds_no_attrs, popds
10+
from .datasets import airds, anc, ds_no_attrs, multiple, popds
1211

1312
mpl.use("Agg")
1413

@@ -119,25 +118,16 @@ def test_kwargs_methods(obj):
119118

120119
def test_kwargs_expand_key_to_multiple_keys():
121120

122-
ds = xr.Dataset()
123-
ds.coords["x1"] = ("x1", range(30), {"axis": "X"})
124-
ds.coords["y1"] = ("y1", range(20), {"axis": "Y"})
125-
ds.coords["x2"] = ("x2", range(10), {"axis": "X"})
126-
ds.coords["y2"] = ("y2", range(5), {"axis": "Y"})
127-
128-
ds["v1"] = (("x1", "y1"), np.ones((30, 20)) * 15)
129-
ds["v2"] = (("x2", "y2"), np.ones((10, 5)) * 15)
130-
131-
actual = ds.cf.isel(X=5, Y=3)
132-
expected = ds.isel(x1=5, y1=3, x2=5, y2=3)
121+
actual = multiple.cf.isel(X=5, Y=3)
122+
expected = multiple.isel(x1=5, y1=3, x2=5, y2=3)
133123
assert_identical(actual, expected)
134124

135-
actual = ds.cf.mean("X")
136-
expected = ds.mean(["x1", "x2"])
125+
actual = multiple.cf.mean("X")
126+
expected = multiple.mean(["x1", "x2"])
137127
assert_identical(actual, expected)
138128

139-
actual = ds.cf.coarsen(X=10, Y=5)
140-
expected = ds.coarsen(x1=10, y1=5, x2=10, y2=5)
129+
actual = multiple.cf.coarsen(X=10, Y=5)
130+
expected = multiple.coarsen(x1=10, y1=5, x2=10, y2=5)
141131
assert_identical(actual.mean(), expected.mean())
142132

143133

0 commit comments

Comments
 (0)