Skip to content

Commit 12ab475

Browse files
committed
test fixes
1 parent 7ffccc9 commit 12ab475

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

cf_xarray/accessor.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ def _getattr(
4545
@functools.wraps(func)
4646
def wrapper(*args, **kwargs):
4747
arguments = accessor._process_signature(func, args, kwargs, keys=keys)
48-
rv = func(**arguments)
49-
if wrap_classes and isinstance(rv, _WRAPPED_CLASSES):
50-
return _CFWrappedClass(obj, rv, accessor)
51-
else:
52-
return rv
48+
49+
result = func(**arguments)
50+
if wrap_classes and isinstance(result, _WRAPPED_CLASSES):
51+
result = _CFWrappedClass(result, accessor)
52+
53+
return result
5354

5455
return wrapper
5556

cf_xarray/tests/test_accessor.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import matplotlib as mpl
2+
import matplotlib.pyplot as plt
13
import pytest
24
import xarray as xr
35
from xarray.testing import assert_identical
@@ -6,20 +8,18 @@
68

79
from . import raise_if_dask_computes
810

11+
mpl.use("Agg")
912
ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(4))
10-
objects = [
11-
pytest.param(ds, marks=pytest.mark.xfail),
12-
ds.air,
13-
pytest.param(ds.chunk({"lat": 5}), marks=pytest.mark.xfail),
14-
ds.air.chunk({"lat": 5}),
15-
]
13+
datasets = [ds, ds.chunk({"lat": 5})]
14+
dataarrays = [ds.air, ds.air.chunk({"lat": 5})]
15+
objects = datasets + dataarrays
1616

1717

1818
@pytest.mark.parametrize("obj", objects)
1919
def test_wrapped_classes(obj):
2020
with raise_if_dask_computes():
21-
expected = obj.resample(time="M").mean("lat")
22-
actual = obj.cf.resample(T="M").mean("Y")
21+
expected = obj.resample(time="M").mean()
22+
actual = obj.cf.resample(T="M").mean()
2323
assert_identical(expected, actual)
2424

2525
# groupby
@@ -41,12 +41,25 @@ def test_other_methods(obj):
4141
assert_identical(expected, actual)
4242

4343

44-
@pytest.mark.parametrize("obj", objects)
45-
def test_plot(obj):
44+
@pytest.mark.parametrize("obj", dataarrays)
45+
def test_dataarray_plot(obj):
46+
4647
obj.isel(time=1).cf.plot(x="X", y="Y")
48+
plt.close()
49+
4750
obj.isel(time=1).cf.plot.contourf(x="X", y="Y")
51+
plt.close()
4852

4953
obj.cf.plot(x="X", y="Y", col="T")
54+
plt.close()
55+
5056
obj.cf.plot.contourf(x="X", y="Y", col="T")
57+
plt.close()
5158

5259
obj.isel(lat=[0, 1], lon=1).cf.plot.line(x="T", hue="Y")
60+
plt.close()
61+
62+
63+
@pytest.mark.parametrize("obj", datasets)
64+
def test_dataset_plot(obj):
65+
pass

ci/environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ dependencies:
55
- pytest-cov
66
- pytest
77
- dask
8+
- matplotlib
89
- netcdf4
910
- xarray

0 commit comments

Comments
 (0)