Skip to content

Commit 59cd665

Browse files
committed
Skip reindexing in finalize_results if reindex is True
Closes #79
1 parent fdfdf10 commit 59cd665

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

flox/core.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ def _finalize_results(
696696
axis: Sequence[int],
697697
expected_groups: pd.Index | None,
698698
fill_value: Any,
699+
reindex: bool,
699700
):
700701
"""Finalize results by
701702
1. Squeezing out dummy dimensions
@@ -730,7 +731,7 @@ def _finalize_results(
730731
finalized[agg.name] = np.where(count_mask, fill_value, finalized[agg.name])
731732

732733
# Final reindexing has to be here to be lazy
733-
if expected_groups is not None:
734+
if not reindex and expected_groups is not None:
734735
finalized[agg.name] = reindex_(
735736
finalized[agg.name], squeezed["groups"], expected_groups, fill_value=fill_value
736737
)
@@ -749,10 +750,11 @@ def _aggregate(
749750
axis: Sequence,
750751
keepdims,
751752
fill_value: Any,
753+
reindex: bool,
752754
) -> FinalResultsDict:
753755
"""Final aggregation step of tree reduction"""
754756
results = combine(x_chunk, agg, axis, keepdims, is_aggregate=True)
755-
return _finalize_results(results, agg, axis, expected_groups, fill_value)
757+
return _finalize_results(results, agg, axis, expected_groups, fill_value, reindex)
756758

757759

758760
def _expand_dims(results: IntermediateDict) -> IntermediateDict:
@@ -1012,7 +1014,9 @@ def _reduce_blockwise(array, by, agg, *, axis, expected_groups, fill_value, engi
10121014
value[mask] = np.nan
10131015
results["intermediates"][0] = value
10141016

1015-
result = _finalize_results(results, agg, axis, expected_groups, fill_value=fill_value)
1017+
result = _finalize_results(
1018+
results, agg, axis, expected_groups, fill_value=fill_value, reindex=reindex
1019+
)
10161020
return result
10171021

10181022

@@ -1155,6 +1159,7 @@ def dask_groupby_agg(
11551159
agg=agg,
11561160
expected_groups=None if split_out > 1 else expected_groups,
11571161
fill_value=fill_value,
1162+
reindex=reindex,
11581163
),
11591164
combine=partial(combine, agg=agg),
11601165
name=f"{name}-reduce",

0 commit comments

Comments
 (0)