Skip to content

Fix SupportsArithmetic import #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import xarray as xr
from xarray import DataArray, Dataset
from xarray.core.arithmetic import SupportsArithmetic
from xarray.core.groupby import GroupBy
from xarray.core.resample import Resample
from xarray.core.rolling import Coarsen, Rolling
Expand Down Expand Up @@ -997,7 +996,7 @@ def _get_possible(accessor, criteria):
return _get_possible(obj.cf, y_criteria)


class _CFWrappedClass(SupportsArithmetic):
class _CFWrappedClass:
"""
This class is used to wrap any class in _WRAPPED_CLASSES.
"""
Expand Down
5 changes: 2 additions & 3 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,15 +1524,14 @@ def test_groupby_special_ops() -> None:
grouped = airds.groupby_bins("lat", np.arange(20, 50, 10))

# __iter__
for (label, group), (cflabel, cfgroup) in zip(grouped, cfgrouped, strict=False):
for (label, group), (cflabel, cfgroup) in zip(grouped, cfgrouped, strict=True):
assert label == cflabel
assert_identical(group, cfgroup)

# arithmetic
# TODO: Extremely buggy!
# 1. cfgrouped - cfgrouped.mean() raises RecursionError
# 2. use_flox=True doesn't preserve attributes for some reason
with xr.set_options(keep_attrs=True):
with xr.set_options(keep_attrs=True, use_flox=True):
expected = grouped - grouped.mean()
actual = grouped - cfgrouped.mean()
assert_identical(expected, actual)
Expand Down
Loading