Skip to content

Fix extra expected groups #113

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
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
4 changes: 3 additions & 1 deletion flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,9 @@ def _factorize_multiple(by, expected_groups, by_is_dask, reindex):
meta=np.array((), dtype=np.int64),
**kwargs,
)
found_groups = tuple(None if is_duck_dask_array(b) else pd.unique(b) for b in by)
found_groups = tuple(
None if is_duck_dask_array(b) else pd.unique(np.array(b).reshape(-1)) for b in by
)
grp_shape = tuple(len(e) for e in expected_groups)
else:
group_idx, found_groups, grp_shape = factorize_(by, **kwargs)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ def test_groupby_bins_indexed_coordinate():
xr.testing.assert_allclose(expected, actual)


def test_mixed_grouping():
@pytest.mark.parametrize("chunk", (True, False))
def test_mixed_grouping(chunk):
if not has_dask and chunk:
pytest.skip()
# regression test for https://github.com/dcherian/flox/pull/111
sa = 10
sb = 13
Expand All @@ -468,6 +471,8 @@ def test_mixed_grouping():
"v1": xr.DataArray((np.arange(sa * sb) % 3).reshape(sa, sb), dims=("a", "b")),
}
)
if chunk:
x["v0"] = x["v0"].chunk({"a": 5})

r = xarray_reduce(
x["v0"],
Expand Down