Skip to content
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

Update groupby attrs tests #6787

Merged
merged 2 commits into from
Jul 15, 2022
Merged
Changes from 1 commit
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
36 changes: 24 additions & 12 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,21 +1152,33 @@ def test_groupby_count(self):
expected = DataArray([1, 1, 2], coords=[("cat", ["a", "b", "c"])])
assert_identical(actual, expected)

@pytest.mark.skip("needs to be fixed for shortcut=False, keep_attrs=False")
def test_groupby_reduce_attrs(self):
@pytest.mark.parametrize("shortcut", [True, False])
@pytest.mark.parametrize("keep_attrs", [None, True, False])
def test_groupby_reduce_keep_attrs(self, shortcut, keep_attrs):
array = self.da
array.attrs["foo"] = "bar"

actual = array.groupby("abc").reduce(
np.mean, keep_attrs=keep_attrs, shortcut=shortcut
)
with xr.set_options(use_flox=False):
expected = array.groupby("abc").mean(keep_attrs=keep_attrs)
assert_identical(expected, actual)

@pytest.mark.parametrize("keep_attrs", [None, True, False])
def test_groupby_keep_attrs(self, keep_attrs):
array = self.da
array.attrs["foo"] = "bar"

for shortcut in [True, False]:
for keep_attrs in [True, False]:
print(f"shortcut={shortcut}, keep_attrs={keep_attrs}")
actual = array.groupby("abc").reduce(
np.mean, keep_attrs=keep_attrs, shortcut=shortcut
)
expected = array.groupby("abc").mean()
if keep_attrs:
expected.attrs["foo"] = "bar"
assert_identical(expected, actual)
with xr.set_options(use_flox=False):
expected = array.groupby("abc").mean(keep_attrs=keep_attrs)
with xr.set_options(use_flox=True):
actual = array.groupby("abc").mean(keep_attrs=keep_attrs)

# values are tested elsewhere, here we jsut check data
# TODO: add check_attrs kwarg to assert_allclose
actual.data = expected.data
assert_identical(expected, actual)

def test_groupby_map_center(self):
def center(x):
Expand Down