Skip to content

Commit 4bc6c15

Browse files
committed
Better handling of RangeIndex for sparse reindexing
1 parent c97e196 commit 4bc6c15

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

flox/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,8 @@ def _factorize_multiple(
23272327
if any_by_dask:
23282328
import dask.array
23292329

2330+
from . import dask_array_ops # noqa
2331+
23302332
# unifying chunks will make sure all arrays in `by` are dask arrays
23312333
# with compatible chunks, even if there was originally a numpy array
23322334
inds = tuple(range(by[0].ndim))

tests/test_core.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,12 +2085,14 @@ def test_datetime_timedelta_first_last(engine, func) -> None:
20852085

20862086
@requires_dask
20872087
@requires_sparse
2088-
def test_reindex_sparse():
2088+
@pytest.mark.xdist_group(name="sparse-group")
2089+
@pytest.mark.parametrize("size", [2**62 - 1, 11])
2090+
def test_reindex_sparse(size):
20892091
import sparse
20902092

20912093
array = dask.array.ones((2, 12), chunks=(-1, 3))
20922094
func = "sum"
2093-
expected_groups = pd.Index(np.arange(11))
2095+
expected_groups = pd.RangeIndex(size)
20942096
by = dask.array.from_array(np.repeat(np.arange(6) * 2, 2), chunks=(3,))
20952097
dense = np.zeros((2, 11))
20962098
dense[..., np.arange(6) * 2] = 2
@@ -2115,9 +2117,10 @@ def mocked_reindex(*args, **kwargs):
21152117
actual, *_ = groupby_reduce(
21162118
array, by, func=func, reindex=reindex, expected_groups=expected_groups, fill_value=0
21172119
)
2118-
assert_equal(actual, expected)
2119-
# once during graph construction, 10 times afterward
2120-
assert mocked_func.call_count > 1
2120+
if size == 11:
2121+
assert_equal(actual, expected)
2122+
# once during graph construction, 10 times afterward
2123+
assert mocked_func.call_count > 1
21212124

21222125

21232126
def test_sparse_errors():

0 commit comments

Comments
 (0)