Skip to content

Commit 72bfffe

Browse files
committed
Got more tests working. Support for elllipsis
1 parent 674bab1 commit 72bfffe

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

cf_xarray/accessor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
)
1515

1616

17+
_DEFAULT_KEYS_TO_REWRITE = ("dim", "coord", "group")
18+
19+
1720
def _get_axis_name_mapping(da: xr.DataArray):
1821
return {"X": "lon", "Y": "lat", "T": "time"}
1922

@@ -23,7 +26,7 @@ def _getattr(
2326
attr: str,
2427
accessor: "CFAccessor",
2528
wrap_classes=False,
26-
keys=("dim",),
29+
keys=_DEFAULT_KEYS_TO_REWRITE,
2730
):
2831
"""
2932
Common getattr functionality.
@@ -142,6 +145,8 @@ def _rewrite_values_with_axis_names(self, kwargs, keys, var_kws):
142145
if isinstance(value, dict):
143146
# this for things like isel where **kwargs captures things like T=5
144147
updates[key] = {self._coords.get(k, k): v for k, v in value.items()}
148+
elif value is Ellipsis:
149+
pass
145150
else:
146151
# things like sum which have dim
147152
updates[key] = [self._coords.get(v, v) for v in value]

cf_xarray/tests/test_accessor.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,43 @@
2222
("resample", {"time": "M"}, {"T": "M"}),
2323
("rolling", {"lat": 5}, {"Y": 5}),
2424
("coarsen", {"lon": 2, "lat": 5}, {"X": 2, "Y": 5}),
25-
# groupby
25+
("groupby", {"group": "time"}, {"group": "T"})
26+
# groupby("time.day")?
2627
# groupby_bins
2728
# weighted
2829
),
2930
)
3031
def test_wrapped_classes(obj, attr, xrkwargs, cfkwargs):
32+
33+
if attr in ("rolling", "coarsen"):
34+
# TODO: xarray bug, rolling and coarsen don't accept ellipsis
35+
args = ()
36+
else:
37+
args = (...,)
38+
3139
with raise_if_dask_computes():
32-
expected = getattr(obj, attr)(**xrkwargs).mean()
33-
actual = getattr(obj.cf, attr)(**cfkwargs).mean()
40+
expected = getattr(obj, attr)(**xrkwargs).mean(*args)
41+
actual = getattr(obj.cf, attr)(**cfkwargs).mean(*args)
3442
assert_identical(expected, actual)
3543

44+
if attr in ("groupby", "groupby_bins"):
45+
# TODO: this should work for resample too?
46+
with raise_if_dask_computes():
47+
expected = getattr(obj, attr)(**xrkwargs).mean("lat")
48+
actual = getattr(obj.cf, attr)(**cfkwargs).mean("Y")
49+
assert_identical(expected, actual)
50+
3651

3752
@pytest.mark.parametrize("obj", objects)
38-
def test_other_methods(obj):
53+
def test_kwargs_methods(obj):
3954
with raise_if_dask_computes():
4055
expected = obj.isel(time=slice(2))
4156
actual = obj.cf.isel(T=slice(2))
4257
assert_identical(expected, actual)
4358

59+
60+
@pytest.mark.parametrize("obj", objects)
61+
def test_args_methods(obj):
4462
with raise_if_dask_computes():
4563
expected = obj.sum("time")
4664
actual = obj.cf.sum("T")

0 commit comments

Comments
 (0)