Skip to content

WIP: Dask array expressions#508

Open
mrocklin wants to merge 6 commits into
xarray-contrib:mainfrom
mrocklin:dask-array
Open

WIP: Dask array expressions#508
mrocklin wants to merge 6 commits into
xarray-contrib:mainfrom
mrocklin:dask-array

Conversation

@mrocklin

Copy link
Copy Markdown

Adds dask-array expression support to flox.

Marking this as WIP mostly because I haven't reviewed it yet. I didn't want to forget about it though.

mrocklin and others added 5 commits June 26, 2026 09:59
Use dask-array expressions for flox groupby operations and route standalone dask_array inputs through an isolated backend. Keep the legacy dask.array path side-effect free, explicitly reject mixed dask backends, and cover xarray, unknown groups, cohorts, and import isolation in focused tests.

Co-Authored-By: Codex <codex@openai.com>
Parametrize selected flox tests over legacy dask.array and standalone dask_array while avoiding collection-time dask_array imports that alter xarray's chunk-manager registry.

Add a standalone arg-reduction preprocess path so dask_array stays on expression graphs for arg reductions.

Co-Authored-By: Codex <codex@openai.com>
Make optional dask-array typing explicit for mypy, skip the legacy-Dask subprocess test when Dask is absent, and include rich in docs dependencies for the cubed notebook.

Co-Authored-By: Codex <codex@openai.com>
Dask-array rolling-window reductions can simplify to a different block grid than the public pre-lowered expression reports. Flox was planning groupby chunks from the pre-simplified grid, which made the final dask-array blockwise extraction inconsistent after lowering and broke map-reduce, cohorts, and xarray's default flox path.

Explicit blockwise had the same issue one step earlier because rechunk_for_blockwise preserved stale spatial chunking before the dask-array backend saw the array. Simplify standalone dask-array inputs before chunk unification/planning, and before blockwise group-boundary rechunking.

Add a small rolling groupby regression that checks all flox paths compute correctly and keep the expected coarser spatial chunk grid.

Co-Authored-By: Codex <codex@openai.com>
Comment thread flox/dask_array.py Outdated
aggregate = partial(_aggregate, combine=combine, agg=agg, fill_value=fill_value, reindex=reindex)

if method == "map-reduce":
reduced = _tree_reduce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use dask_array.reduction

Comment thread flox/dask_array.py
group_chunks = ((len(expected_groups),),)

else:
assert chunks_cohorts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterate over cohort;s use reduction for tree-reduction over each cohort; then concatenate across cohorts.

Replace the private dask_array _tree_reduce import in the standalone dask-array backend with the public dask_array.reduction API for both map-reduce and per-cohort reductions.

Dask-array simplification can change the block grid used by rolling-window inputs, so recompute cohort block membership after simplifying and unifying chunks. That keeps cohort subsetting aligned with the graph that will actually be lowered and computed.

Co-Authored-By: Codex <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants