Skip to content

Commit ebcd06c

Browse files
committed
fix tests
1 parent b6d767d commit ebcd06c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

flox/core.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ def rechunk_for_cohorts(
639639
return array.rechunk({axis: newchunks})
640640

641641

642-
def rechunk_for_blockwise(array: DaskArray, axis: T_Axis, labels: np.ndarray) -> DaskArray:
642+
def rechunk_for_blockwise(
643+
array: DaskArray, axis: T_Axis, labels: np.ndarray, *, force: bool = True
644+
) -> DaskArray:
643645
"""
644646
Rechunks array so that group boundaries line up with chunk boundaries, allowing
645647
embarrassingly parallel group reductions.
@@ -672,11 +674,16 @@ def rechunk_for_blockwise(array: DaskArray, axis: T_Axis, labels: np.ndarray) ->
672674
return array
673675

674676
Δn = abs(len(newchunks) - len(chunks))
675-
if (Δn / len(chunks) < BLOCKWISE_RECHUNK_NUM_CHUNKS_THRESHOLD) and (
676-
abs(max(newchunks) - max(chunks)) / max(chunks) < BLOCKWISE_RECHUNK_CHUNK_SIZE_THRESHOLD
677+
if force or (
678+
(Δn / len(chunks) < BLOCKWISE_RECHUNK_NUM_CHUNKS_THRESHOLD)
679+
and (
680+
abs(max(newchunks) - max(chunks)) / max(chunks) < BLOCKWISE_RECHUNK_CHUNK_SIZE_THRESHOLD
681+
)
677682
):
678683
# Less than 25% change in number of chunks, let's do it
679684
return array.rechunk({axis: newchunks})
685+
else:
686+
return array
680687

681688

682689
def reindex_(
@@ -2496,7 +2503,7 @@ def groupby_reduce(
24962503
):
24972504
# Let's try rechunking for sorted 1D by.
24982505
(single_axis,) = axis_
2499-
array = rechunk_for_blockwise(array, single_axis, by_)
2506+
array = rechunk_for_blockwise(array, single_axis, by_, force=False)
25002507

25012508
if _is_first_last_reduction(func):
25022509
if has_dask and nax != 1:

0 commit comments

Comments
 (0)