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

Remove None output from _get_expected_groups #152

Merged
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
11 changes: 6 additions & 5 deletions flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ def _is_arg_reduction(func: str | Aggregation) -> bool:
return False


def _get_expected_groups(by, sort, *, raise_if_dask=True) -> pd.Index | None:
def _get_expected_groups(by, sort: bool) -> pd.Index:
if is_duck_dask_array(by):
if raise_if_dask:
raise ValueError("Please provide expected_groups if not grouping by a numpy array.")
return None
raise ValueError("Please provide expected_groups if not grouping by a numpy array.")
flatby = by.reshape(-1)
expected = pd.unique(flatby[~isnull(flatby)])
return _convert_expected_groups_to_index((expected,), isbin=(False,), sort=sort)[0]
Expand Down Expand Up @@ -1152,7 +1150,10 @@ def dask_groupby_agg(
else:
intermediate = applied
if expected_groups is None:
expected_groups = _get_expected_groups(by_input, sort=sort, raise_if_dask=False)
if is_duck_dask_array(by_input):
expected_groups = None
else:
expected_groups = _get_expected_groups(by_input, sort=sort)
group_chunks = ((len(expected_groups),) if expected_groups is not None else (np.nan,),)

if method == "map-reduce":
Expand Down
2 changes: 1 addition & 1 deletion flox/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def xarray_reduce(
f"Please provided bin edges for group variable {idx} "
f"named {group_name} in expected_groups."
)
expect_ = _get_expected_groups(b_.data, sort=sort, raise_if_dask=True)
expect_ = _get_expected_groups(b_.data, sort=sort)
else:
expect_ = expect
expect_index = _convert_expected_groups_to_index((expect_,), (isbin_,), sort=sort)[0]
Expand Down