Skip to content

Commit

Permalink
Fix unique
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Oct 20, 2022
1 parent 336e2bb commit c370b5d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def _get_optimal_chunks_for_groups(chunks, labels):
return tuple(newchunks)


def _unique(a):
def _unique(a: np.ndarray):
"""Much faster to use pandas unique and sort the results.
np.unique sorts before uniquifying and is slow."""
return np.sort(pd.unique(a))
return np.sort(pd.unique(a.reshape(-1)))


@memoize
Expand Down Expand Up @@ -897,7 +897,7 @@ def _grouped_combine(
# when there's only a single axis of reduction, we can just concatenate later,
# reindexing is unnecessary
# I bet we can minimize the amount of reindexing for mD reductions too, but it's complicated
unique_groups = _unique(tuple(flatten(deepmap(listify_groups, x_chunk))))
unique_groups = _unique(np.array(tuple(flatten(deepmap(listify_groups, x_chunk)))))
unique_groups = unique_groups[~isnull(unique_groups)]
if len(unique_groups) == 0:
unique_groups = [np.nan]
Expand Down

0 comments on commit c370b5d

Please sign in to comment.