Skip to content

Array expressions - #12207

Open
mrocklin wants to merge 243 commits into
dask:mainfrom
mrocklin:array-expr
Open

mrocklin wants to merge 243 commits into
dask:mainfrom
mrocklin:array-expr

Conversation

@mrocklin

Copy link
Copy Markdown
Member

I went through array expressions with Claude and filled them out. This is a massive PR.

I was paying attention during execution, but not very close attention. There are some things that aren't great I'm sure, but on balance it seems decent. The test suite passes. I think next steps include:

  • Try it out on real problems
  • Work on Xarray to help it deal with array expressions
  • Benchmark

Regarding merging, I think it should be easy for us to merge things on this topic. I think it should be difficult for us to switch the default.

@github-actions

github-actions Bot commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

0 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ❌ ±0 

Results for commit 033e575. ± Comparison against base commit 8d2cc26.

♻️ This comment has been updated with latest results.

@mrocklin

Copy link
Copy Markdown
Member Author

OK, I've added some optimizations here, as well as some tools to visualize what's going on. I've also updated xarray to use this in a branch. Notebooks here:

For people who don't like clicking on links, here is an example:

import dask.array as da
x = da.ones((20000, 20000))
x.expr
 Operation           Shape    Bytes     Chunks  
  Ones       (20000, 20000)  3.0 GiB  4096×4096  
x.dot(x.T - x.mean(axis=0))[:5, :20].expr
  Operation                           Shape    Bytes       Chunks  
  Getitem                           (5, 20)    800 B         5×20  
  └ Sum                      (20000, 20000)  3.0 GiB    4096×4096  
    └ Sum                 (20000, 5, 20000)   15 GiB  4096×1×4096  
      └ Tensordot         (20000, 5, 20000)   15 GiB  4096×1×4096  
        ├ Ones               (20000, 20000)  3.0 GiB    4096×4096  
        └ Sub                (20000, 20000)  3.0 GiB    4096×4096  
          ├ Transpose        (20000, 20000)  3.0 GiB    4096×4096  
          │ └ Ones           (20000, 20000)  3.0 GiB    4096×4096  
          └ Mean Agg                (20000)  156 kiB         4096  
            └ Mean Chunk         (5, 20000)  781 kiB       1×4096  
              └ Ones         (20000, 20000)  3.0 GiB    4096×4096  
x.dot(x.T - x.mean(axis=0))[:5, :20].expr.simplify()
  Operation                   Shape    Bytes   Chunks  
  Sum                       (5, 20)    800 B     5×20  
  └ Sum                  (5, 5, 20)  3.9 kiB   5×1×20  
    └ Tensordot          (5, 5, 20)  3.9 kiB   5×1×20  
      ├ Ones             (5, 20000)  781 kiB   5×4096  
      └ Sub             (20000, 20)  3.1 MiB  4096×20  
        ├ Transpose     (20000, 20)  3.1 MiB  4096×20  
        │ └ Ones        (20, 20000)  3.1 MiB  20×4096  
        └ Mean Agg             (20)    160 B       20  
          └ Mean Chunk      (5, 20)    800 B     1×20  
            └ Ones      (20000, 20)  3.1 MiB  4096×20  

But you should look at the notebooks. They have color.

@mrocklin

Copy link
Copy Markdown
Member Author

Running through some of the coiled xarray benchmarks. Still plenty to do to make things smooth. It's pretty easy going though.

@mrocklin

Copy link
Copy Markdown
Member Author

OK, xarray benchmarks mostly work (and are marginally faster on my machine than legacy). Most notably we're able to fuse pretty aggressively for free. I've also removed cull and other low-level optimizations.

I've also done a little work on flox: https://github.com/xarray-contrib/flox/compare/main...mrocklin:flox:dask-array-expr?expand=1

Still some issues I'm sure, but decreasing. The first xarray benchmark I ran had a bunch of things that needed to be fixed. The last couple I ran were fine without effort. The first notebook benchmark is here if people want to run it.

This is now at a point where we probably want an actual xarray user to take it for a spin. I'm sure that there are some issues.

@mrocklin

Copy link
Copy Markdown
Member Author

cc @dcherian @jhamman

sliced_input = new_collection(input_array)[input_index]

# Don't push slice through if it would create empty arrays on non-reduced axes.
# Reductions on empty non-reduced dimensions cause issues with task aggregation.

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.

this sounds like a bug but maybe I'm misunderstanding?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure this is a bug, no. This is saying that we don't want to push slices down through to the underlying array if we're reducing on that dimension.

In general, slicing and reductions can interact. Consider the following:

x = da.random.random(...)

x.mean(axis=1)[:5]

This is better done as

x[:5].mean(axis=1)

It gets complicated though with dimensions if they collapse or go away. We really only want to slice through dimensions that aren't being affected by the reduction.

@dcherian dcherian Dec 31, 2025 •

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.

Don't push slice through if it would create empty arrays on non-reduced axes.

The comment seems to be talking about non-reduced axes though (or am I misunderstanding; and the next line

Reductions on empty non-reduced dimensions cause issues with task aggregation.

sounds like an issue with handling .mean(array_with_shape(0,1,2), axis=0) (not sure what numpy does here either).

@crusaderky

Copy link
Copy Markdown
Collaborator

I think we should not merge into main a PR that is functionally impossible for humans to review.

Some random passing observations:

  • This PR is about array expr, however there are many changes in dask.dataframe. What do they do? Is it necessary for them to be in the same PR?
  • This PR also tweaks the pytest config switch that enables array query planning. What was the problem with the previous one? Why does the change need to be in the same PR?
  • I see a bunch of explanation files from claude; they shouldn't be merged into main IMHO.
  • This also tampers with coverage config. It should be a different, properly discussed, PR.
  • I've run a quick spot check of dask/tests (e.g. not dask/array/tests. I've spotted e.g. test_array_delayed, which as the name suggests feeds an array into a delayed. The test performs a bunch of checks on the details of the old implementation, which rightfully won't work with dask-expr. However, the whole test is xfailed out, effectively making it impossible to know if the high-level, user-facing functionality is now broken or if it's just a trivial matter of internals.

I think this PR constitutes a good prototype starting point from which one can start exfiltrating smaller, self-contained, and - crucially - human-reviewable PRs.

@mrocklin

Copy link
Copy Markdown
Member Author

Thanks for the comments. Some responses:

I think we should not merge into main a PR that is functionally impossible for humans to review.
I think this PR constitutes a good prototype starting point from which one can start exfiltrating smaller, self-contained, and - crucially - human-reviewable PRs.

I appreciate the concern about human readability. I think that the issue of human readability might be a couple of possible causes

  • The code is just bad AI slop
  • The changes are very large

In the first case I'd agree that one shouldn't merge things in. In the second case I'm not sure. I could also slam this repo with 100 self-contained PRs, but the changes would be more or less the same as what's here. I'm not sure that it would be easier on humans to consume the many smaller PRs over the one big PR. Array expressions are, intrinsically, a large change. There's a certain amount of pain here that we'd have to go through regardless.

The specific issues around secondary changes seem valid to me though. Thank you for raising them.

however there are many changes in dask.dataframe. What do they do? Is it necessary for them to be in the same PR?

The array/dataframe boundary is particularly interesting / challenging. This happens in operations like df.values or da.map_blocks(pd.DataFrame). Previously these navigated between Dataframe Exprs and HLGs. This was unpleasant and resulted in just forgetting the Expr structure. Now we keep the Expr structure, but there's certainly more to do here to make sure that optimizations pass smoothly between things (this gets even stranger with Xarray). What's here isn't optimal, but I do think that it is strictly better than the previous state.

This PR also tweaks the pytest config switch that enables array query planning. What was the problem with the previous one? Why does the change need to be in the same PR?

When developing it was smoother to xfail everything that didn't work with array expressions, and then work through the xfails. This results in a test suite that looks more or less exactly like the current test suite (the diff in tests is very small, which I think is good). This way of developing is what motivated the change in the pytest config.

I see a bunch of explanation files from claude; they shouldn't be merged into main IMHO.

I think that this is a larger discussion. I think that we should start to include more AI-forward documentation and structure in this repository. I think that this will help us automate maintenance in the future. I appreciate that this is a longer conversation though. I'm happy to block merging this on some resolution of that conversation. I'll raise another issue.

I've spotted e.g. test_array_delayed

I'll take a look.

from which one can start exfiltrating smaller, self-contained, and - crucially - human-reviewable PRs.

Just to set expectations, I do not intend to do this level of work. I'm happy to spend a week or two pushing on this. I think that doing this feature by feature and getting review on each one would take several months.

@mrocklin mrocklin mentioned this pull request Dec 30, 2025
@mrocklin

Copy link
Copy Markdown
Member Author

I'll raise another issue.

#12210

@crusaderky

crusaderky commented Dec 30, 2025 •

Copy link
Copy Markdown
Collaborator

I'm not sure that it would be easier on humans to consume the many smaller PRs over the one big PR.

It most certainly would.

I think that doing this feature by feature and getting review on each one would take several months.

Yes, this is a very major feature which is both high cost and high value. Several months are to be expected.

I'm happy to spend a week or two pushing on this.

To me, this implies that either

  • reviewers should blindly trust Claude, or
  • reviewers should spend the months worth of effort going through Claude's changes, without the developer bothering to do the same first.

I am not in any way against using AI to write an initial prototype to kickstart human-led, human-understood development. What I am strongly against is using AI to push a finished product and call it a day, with humans involved at most in giving it a very passing glance. This is, frankly, a recipe for disaster.

@crusaderky crusaderky left a comment

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.

.

@mrocklin

Copy link
Copy Markdown
Member Author

It most certainly would.

Thanks for your opinion here. Respectfully I'll disagree.

What I am strongly against is using AI to push a finished product and call it a day, with humans involved at most in giving it a very passing glance.

I hear your concerns. I certainly wouldn't want to spend months reviewing an AI Slop PR. This isn't that. I've done a fair bit of work to guide development.

Several months are to be expected

I'm certainly not going to do several months of work on this. What I'm hearing from you then is that you're -1 on this PR. That's a fine position to take. That -1 won't necessarily block development though.

My own thoughts on merging this are in the original post:

Regarding merging, I think it should be easy for us to merge things on this topic. I think it should be difficult for us to switch the default.

This section of the code is not on by default, and is mostly unusable today. I think that it's good and warranted to be picky about changes outside of the config feature flag (thank you for spending your time doing this), but that requiring months of work on the stuff within the feature flag area is not warranted and is not the right choice for the project.

@dcherian

Copy link
Copy Markdown
Collaborator

I agree with Matt here, and trust his word on this being human-designed and human-guided development.

This is indeed an extremely large change. It is also a possibly-very-large improvement that would never be finished or meaningfully explored without a large dose of AI given how little maintainer bandwidth is available at this repo.

Perhaps the thing to discuss are the actual plan, design docs, and skills files. Since the Github UI is useless for such large PRs, would it make sense to open a new PR with just those files, and talk through the top-level design prompts?

@mrocklin

Copy link
Copy Markdown
Member Author

Earlier @crusaderky wrote the following:

To me, this implies that either

  • reviewers should blindly trust Claude, or
  • reviewers should spend the months worth of effort going through Claude's changes, without the developer bothering to do the same first.

While I appreciate the general concern, I think that this is perhaps a little hyperbolic. There's plenty of space between "blind trust" and "spend months worth of effort". There are many ways that we can build confidence without spending months of effort reading every line. One of those ways of course is the dask test suite, xarray test suite, etc. Those are pretty strict checks.

Another ways is by, well, using even more AI. Here is an interaction with Claude, asking it to review everything outside of the _array_expr branch to see what's necessary and its initial response. Of course this isn't definitiive, but it maybe helps at least to explain why changes exist.

I'll still dig in a little and see what can be removed. I wasn't thinking of this PR as being read to merge just yet, I'd rather have people bang on it a little but it seems like people are judging it that way so I might as well make it ready.

Prompt

I'd like to clean up our branch here relative to main by ...

  1. removing things that aren't strictly necessary (like maybe moving much of claude/settings.json back to settings.local.json)
  2. reviewing all changes outside of dask/array/_array_expr to see if they are strictly necessary

Do a thorough review of the entire diff outside of _array_expr to see the changes we have, and what we might consider reverting to see if it's necessary.

Response

⏺ Summary of Changes Outside _array_expr

  1. Claude Tooling (candidates for removal/moving)
File Status Recommendation
.claude/settings.json Generic permissions Move to settings.local.json - these are user-specific
.claude/skills/* Project skills Keep - useful for development
CLAUDE.md Project docs Keep - valuable for any contributor using Claude
designs/*.md Design docs Keep - independent of Claude
plans/*.md Plans Keep - independent of Claude
  1. Project Config (mostly keep)
File Changes Recommendation
.gitignore Added *.zarr, *.ipynb Keep - sensible ignores
conftest.py Added --array-expr flag handling Keep - essential for testing
pyproject.toml Removed array_expr markers Keep - cleanup of unused markers
continuous_integration/scripts/run_tests.sh --runarrayexpr → --array-expr Keep - consistent flag naming
  1. Core Dask Changes (mostly necessary)
File Changes Recommendation
dask/_expr.py Significant: rich tables, list traversal for Fused, _optimize_list_operands flag, default fuse=True Keep - needed for array-expr functionality
dask/_rich_table.py New file for expression visualization Review - could be optional, but nice for debugging
dask/_task_spec.py Added dask_future duck-typing Might revert - may not be strictly needed
dask/_pandas_compat.py np.random.seed(42) in test helper Keep - test determinism
dask/base.py Handle xarray DataArrays, persist protocol Keep - fixes edge cases
dask/delayed.py Handle nested keys from arrays Keep - needed for array integration
dask/tokenize.py h5py tokenization Review - needed for h5py arrays
  1. Array Module Changes (mostly necessary)
File Changes Recommendation
dask/array/init.py Import switching based on mode Keep - core routing logic
dask/array/core.py Unknown chunks handling, from_zarr fix, blocks indexer fix Keep - bug fixes and compatibility
dask/array/ma.py Late import dask.array as da Keep - needed for mode-switching
dask/array/rechunk.py Delegate to expr_rechunk when enabled Keep - essential routing
dask/array/reductions.py Import routing for arg_reduction Keep - essential
dask/array/routines.py Late import in _average Keep - needed for mode-switching
dask/array/utils.py Minor Keep
dask/array/tests/conftest.py EncapsulateNDArray mock class Keep - test infrastructure
  1. DataFrame Changes (needed for interop)
File Changes Recommendation
dask/dataframe/dask_expr/_array.py New: DataFrame↔Array conversion Keep - needed for interop
dask/dataframe/dask_expr/_collection.py Array-expr mode handling Keep - interop
dask/dataframe/dask_expr/_expr.py _layer(), _table(), Fused handling Keep - consistency with base Expr
dask/dataframe/dask_expr/_visualize.py New: rich table for DataFrames Keep - consistency with array
  1. New Test Files
File Recommendation
dask/tests/test_expr.py (additions) Keep
dask/tests/test_rich_table.py Keep if rich tables kept
dask/array/tests/test_array_expr_fusion.py Keep

Recommended Actions

Can safely revert/move:

  1. .claude/settings.json → Merge into settings.local.json and remove from tracking

Should investigate before reverting:
2. dask/_task_spec.py - The dask_future duck-typing may not be needed; check if tests pass without it
3. dask/_rich_table.py + related _table() methods - Nice for debugging but adds complexity; could be made optional

Should keep:

  • Everything else appears necessary for array-expr functionality or is general improvement

Comment on lines +565 to +566
if first_block >= len(cumsum) - 1:
return None, None # Out of bounds

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.

seems like this is an invalid slice and should be an error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the spirit of testing to see how good Claude is at this, I posed this question to it. @dcherian I'd be curious about your thoughts on the response (is it good? did it miss an important point?) I think my motivation in this is less about solving this specific problem (although I acknowledge that it's important to solve) and more about us calibrating how to work with things:

My colleague makes the following question about lines 565:566 in
dask/array/_array_expr/_blockwise.py

seems like this is an invalid slice and should be an error?

Thoughts on this? (he might be wrong)

⏺ Read(dask/array/_array_expr/_blockwise.py)
⎿  Read 20 lines

⏺ The colleague raises a fair point, but I think the current behavior is correct.

When first_block >= len(cumsum) - 1, it means the slice starts beyond all blocks (e.g., x[1000:] on a 100-element array). Returning (None, None) causes the optimization to be skipped, and the slice gets applied to the full output.

This matches NumPy's forgiving slice semantics:

np.arange(100)[1000:1001]
array([], dtype=int64) # Empty, not an error

So rather than raising an error, we let the slice operation produce an empty result naturally. The None, None return is a signal to skip optimization, not an error condition.

That said, one could argue we should handle this case explicitly in the coarse optimization by creating an empty result directly, but skipping the optimization and letting normal slice semantics handle it is simpler and equally correct.

I see how this would produce a correct result, but I wonder if it would produce an optimially
efficient result. Would it be better to inject a slice into the child to make sure that we slice down
to nothing earlier rather than later?

⏺ Good point. Let me trace through what happens:

For out-of-bounds slices (like y[1000:1001] on 100 elements):

  • We already handle this optimally - line 594 creates block_ranges.append((0, -1)) and then line 634 injects slice(0, 0) into inputs. Zero blocks computed.

For out-of-bounds integers (like y[1000]):

  • We return None, skipping optimization
  • The full blockwise executes, then the integer index raises IndexError

The user's concern applies to the integer case - we compute everything just to error. But since it's an error path anyway, I'd argue it's not worth the complexity to optimize. Users shouldn't hit this in normal operation.

That said, if we wanted to handle it, we could change line 584-585 from:

if first is None:
return None # Out of bounds

to inject an empty slice and let it error on a zero-size result instead:

if first is None:
block_ranges.append((0, -1)) # Empty - will error on integer index
output_adjustments.append(0) # Keep as integer to trigger IndexError

But this adds complexity for an edge case that's already an error. I'd leave it as-is unless there's a real-world scenario where this matters.

@dcherian

dcherian commented Jan 1, 2026

Copy link
Copy Markdown
Collaborator

Latest commit works beautifully. From a dev perspecitive I was surprised to not see FromArray(Getitem) and had to stare at the shapes to understand that the pushdown had worked.

image

@crusaderky

Copy link
Copy Markdown
Collaborator

There are many ways that we can build confidence without spending months of effort reading every line. One of those ways of course is the dask test suite, xarray test suite, etc. Those are pretty strict checks.

The dask test suite suffers from a fairly low 88% coverage, and the codecov reports have been broken for the last year, which informs me that nobody has looked at them since either (I'm busy fixing them now).

I think I would be much more malleable to push forward with this if

  • there were minimal, strictly necessary changes outside of dask/array/_array_expr, pushing as much as possible to a bunch of prerequisite PRs, and
  • test coverage was very thorough throughout dask/array.

Additionally, to my understanding the work for dask.expr can be split in two:

  • functions and modules that are currently marked as raise_not_implemented_error in dask/array/__init__.py
  • everything else, which on paper should work

It should be trivial to have raise_not_implemented_error raise pytest.skip instead of NotImplementedError if it detects some flag and to run the full test suite on array expr. I expect a lot of red tests there already; this could lead to a smaller PR (hopefully much smaller) that fixes everything that isn't marked by raise_not_implemented_error.

@mrocklin

mrocklin commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

The dask test suite suffers from a fairly low 88% coverage, and the codecov reports have been broken for the last year, which informs me that nobody has looked at them since either (I'm busy fixing them now).

Thanks for working on that.

there were minimal, strictly necessary changes outside of dask/array/_array_expr, pushing as much as possible to a bunch of prerequisite PRs, and

The changes are pretty tied to the work here. I don't know how separable these things are. Looking through the changes outside of _array_expr described in this comment are there particular areas that concern you?

test coverage was very thorough throughout dask/array.

To be clear, this implementation handles the entire dask/array test suite (with a couple of exceptions, mostly around explicit tests for low-level task graph structure). Coverage is pretty much about as high as it can get without extending legacy dask array tests.

  • functions and modules that are currently marked as raise_not_implemented_error in dask/array/init.py
  • everything else, which on paper should work

The first category is done. Maybe I wasn't clear on this earlier. This PR is a complete re-implementation of dask array with expressions. Or maybe you're asking a different question and I'm not understanding.

To be fully explicit, if you run

pytest dask/array --array-expr

You run the entire dask array test suite with array expressions and everything passes.

@mrocklin

mrocklin commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

Latest commit works beautifully. From a dev perspecitive I was surprised to not see FromArray(Getitem) and had to stare at the shapes to understand that the pushdown had worked.

Yeah, FromArray's are able to absorb slices into them, so there was an intermediate getitem, but simplification pushed it all the way down, and then more simplification removed/absorbed it into the FromArray. (This is also how we get culling now)

@crusaderky

Copy link
Copy Markdown
Collaborator
  • functions and modules that are currently marked as raise_not_implemented_error in dask/array/init.py
  • everything else, which on paper should work

The first category is done. Maybe I wasn't clear on this earlier. This PR is a complete re-implementation of dask array with expressions. Or maybe you're asking a different question and I'm not understanding.

I did not explain clearly.
Yes, I understood that this PR covers both points, and this is the problem.
It includes many changes necessary to implement the functions marked by raise_not_implemented_error.
However, such changes don't need to be part of a singular, 35k-lines-long PR.

It should be feasible to

  1. Implement a temporary flag that changes the behaviour of raise_not_implemented_error to throw pytest.skip instead of NotImplementedError (you still want to raise NotImplementedError in downstream projects)
  2. Write a PR that turns the full test suite green with --array-expr; in other words fully fixing all the functionality that already exists without implementing any of the functions marked by raise_not_implemented_error.
  3. Write follow-up PRs for the functions and modules marked by raise_not_implemented_error.

The cumulation of (2) and (3) would result in the current PR. The goal is to have something that is human-readable and human-verifiable.

Looking through the changes outside of _array_expr described in #12207 (comment) are there particular areas that concern you?

There are many things in that list that can be moved to separate PRs, to be reviewed separately.

Namely, I suspect that all the changes to dask.dataframe and dask.bag could be moved to separate PRs, as they should not rely on significant changes in dask.array._array_expr? (transitorily, relevant tests in dask/dataframe/tests and dask/bag/tests would gain @pytest.mark.normal_and_array_expr). This is under the assumption that dask.array._array_expr.Array is mostly good in main, save for methods that ought not to be relevant for conversion to/from bag/dataframe.

@mrocklin

mrocklin commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

Latest commit works beautifully.

I'm glad. For others not tracking the Xarray/Flox stuff there's some conversation happening here (for context I also have branches on xarray and flox that integrate all of this).

In the discussion there I show how a relatively high level prompt, along with some guidance and the structure provided in this repo, was able to turn a somewhat non-trivial request for an optimization into fairly reasonable code with mild effort.

@mrocklin

mrocklin commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

It should be feasible to ...

You're right. It probably is feasible to do that. I appreciate that this is how you would have done this work.

To be clear, my sense from your comment is that you now also expect me to spend time to do this work. Is that right? The goal being for me to spend time to make it easier for you to review. Correct? I appreciate the value in doing work to make review easier.

However I'm not sure that the ROI is strictly positive in this case. I'm not sure that things are quite as separable as you think. If you're interested, you might actually start going through this PR commit by commit (say, the first five commits) each of which are entirely human readable. I think you'll find that the thought process is not very different from how you were thinking.

The goal is to have something that is human-readable and human-verifiable.

Zooming out, I'm not sure that I fully agree with this goal. I think that we need to establish sufficient confidence in this code so that merging it has a positive ROI (more good comes of it than bad), and I agree with you that human-readability/verifiability is one way to build confidence. However, I think that there are many ways to establish confidence (tests, AI, benchmarks, etc.) beyond reviewing everything by hand and that we may be at a point where we need to rely on them more.

AI development is such that we're now much better at authoring code than we were before. I'd say about 90% of the 234 commits in this repo are the kind of self-contained human-readable units of work that you'd like. Each comes with code, tests, a description, etc.. Each took maybe 15 minutes on average to complete. By our traditional review methods I'd guess that each would take a couple days to get through the kind of thorough back-and-forth review that we used to do. I'm certainly not going to spend the time on this and I suspect that no one else will either. This project doesn't have that bandwidth (although I appreciate your recent energy here). I think that we'll need to change how we work.

I'm not saying "and so we should just merge this and not verify anything". I think though that we'll need to get creative and change how we think about reviewing work. I'm very open to engaging on that topic. However I'm not interested in being told to redo this work in a different manner because that's how the reviewer would have done it, especially if that approach seems like it would be a very large investment of time. (my apologies if that response is frustrating).

@mrocklin

mrocklin commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

Namely, I suspect that all the changes to dask.dataframe and dask.bag could be moved to separate PRs, as they should not rely on significant changes in dask.array._array_expr?

The change to dask.bag is an xfail because the test depends on dask array and uses HLGs

The changes in dask dataframe, as described above, are pretty tied in to dask array because of interactions with dask arrays in methods like df.values and x.map_blocks(pd.DataFrame). This work is actually one of the trickier and unsolved bits in the array expression system.

Do you have other questions?

One suggestion that I have for you (I hope you forgive the suggestion) would be to actually bring up a tool like claude code and ask it questions of the diff. I suspect that it could provide answer I just gave quite easily, and could easily answer several other questions you would come up with. I think that your intellect and critical eye, combined with AI's ability to pore through a diff, would actually be a really powerful combination. I'd really welcome that kind of scrutiny. I think that it could do a lot of good if you were interested in trying that out.

mrocklin and others added 3 commits January 2, 2026 10:15
- designs/array-expr.md: Architecture principles and patterns
- plans/array-expr-migration.md: Prioritized work list and TDD workflow
- .claude/skills/: Migration skill with phased guidance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Implement structured array field access (e.g., x['a'], x[['a', 'b']])
using map_blocks, matching the traditional implementation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Remove module-level skips and add individual xfail markers for tests
that don't yet work with array-expr. This makes test coverage visible
and progress trackable.

- test_array_core.py: 221 pass, 240 xfail
- test_array_utils.py: 30 pass, 2 xfail
- test_rechunk.py: 79 pass, 3 xfail
- test_dispatch.py: kept skip (fundamental API difference)
- test_routines.py: kept skip (too many unimplemented)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
mrocklin and others added 10 commits January 2, 2026 10:16
Integer indices must remove dimensions even when the dimension is
size 1. Previously, size-1 dims were always converted to slice(None)
which incorrectly preserved the dimension.

Also adds regression tests for this fix and the previous rechunk fixes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Route color= options to task graph visualization since expression
  visualization doesn't support node coloring
- Remove xfail on test_mixed_dask_array_multi_dimensional (Rechunk now
  has npartitions)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Handle empty slices ([:0]) on broadcast dimensions correctly
- Handle integer indices on broadcast dims by mapping to 0
- Don't push empty slices through reductions (causes invalid task graphs)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Remove .claude/settings.json (use settings.local.json instead)
- Change _da to da in _average() for consistency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The legacy BlockView in core.py was using from_graph to return
array-expr Arrays when array-expr mode was enabled. This is
unnecessary since array-expr mode uses its own BlockView from
slicing/_blocks.py via the .blocks property.

Update tests to use x.blocks instead of BlockView(x) directly,
which is the recommended API and works correctly in both modes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
When a Blockwise has adjust_chunks set, we can't push the exact slice
through because input/output chunk boundaries don't align. However, we
can still optimize by selecting only the input blocks that contribute
to the needed output blocks, then trimming the output if necessary.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Use ComplexWarning from numpy_compat instead of np.exceptions.ComplexWarning
which doesn't exist in older NumPy versions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Match legacy behavior: compute result_type on original values before
converting to arrays, preserving NumPy's scalar promotion semantics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
mrocklin and others added 2 commits January 3, 2026 08:13
Add coarse_blockdim() to prefer larger chunks when combining arrays
with different chunk granularities. When chunk boundaries align
(coarse boundaries are a subset of fine boundaries), use the coarser
chunking to reduce task overhead. Falls back to common_blockdim when
boundaries don't align.

This fixes chunk explosion in xarray groupby patterns where a
shuffle-indexed array (with per-element chunks) is combined with
an array that has nice chunking.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
For contiguous indexing patterns like np.repeat, this produces output
chunks aligned with input chunks (4 chunks instead of 120). Scattered
patterns like np.tile are unchanged.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Comment on lines +22 to +24
indexer = np.repeat(np.arange(100), 3) # [0,0,0,1,1,1,...,99,99,99]
result = x[indexer, :]

@dcherian dcherian Jan 4, 2026 •

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.

Here is an example of why a user might chain rechunk with vindex or take; and why dask should optimize that --- What if I had np.repeat(np.arange(100), 30_000) and then decided those chunk sizes were too big and applied a rechunk?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is helpful. I didn't pass rechunks through shuffles, but I did make sure that take/vindex don't create chunks that are larger than the chunks of the inputs.

This still doesn't fix the broader problem of "we decided to change the chunking later on". I do see value in this. I think that I'm first trying to find ways to solve problems that don't require the user to know to rechunk. We'll want rechunk push-through anyway though.

return SliceSlicesIntegers(x, index, allow_getitem_optimization)


def take(x, index, axis=0):

@dcherian dcherian Jan 4, 2026 •

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.

I've never understood why the core take logic is different from vindex. I worked hard to optimize the latter in https://github.com/dask/dask/pull/11625/changes. Can (should) that be reused?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The logic between vindex with a single axis and take is now unified in d1216dc . I think it should exhibit "best of both worlds" in terms of behaviors, but review on that is welcome.

mrocklin and others added 3 commits January 4, 2026 14:59
Both now benefit from Shuffle's _accept_shuffle optimization hooks.
Extract _compute_indexer helper for consecutive index grouping.
Fix _vindex_slice_and_transpose for uint64 dtype and sparse matrices.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Prevents unbounded chunk growth when using patterns like np.repeat
with large repeat factors. Groups larger than the max input chunk
size on the shuffle axis are now split into limit-sized pieces.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The exact taker/sorter count depends on chunk sizing. The test now
verifies correctness and that shuffle infrastructure is used, rather
than asserting specific counts which are brittle to implementation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jacobtomlinson

Copy link
Copy Markdown
Member

A few high-level thoughts about this PR:

I think it should be easy for us to merge things on this topic. I think it should be difficult for us to switch the default.

In the future I agree with this. However, currently we are still on this journey to a well oiled AI coding ecosystem. This is the first well-written big AI PR opened in this project, everything else to this point has been slop. We all need to build the muscles around reviewing non-slop. Once we do, it will get easier to merge things like this.

I agree with Matt here, and trust his word on this being human-designed and human-guided development.

@mrocklin you've not done much reviewing lately so you may not be as burned as some of us are with the current pattern of novice contributors giving an issue link to claude, generating a poor quality PR and opening it for us to review. It's getting tiring.

However, this PR is not that. This is the result of a very senior engineer guiding an AI to implement something that is well designed. I'm really excited that this is what the future of development will look like.

I'm apprehensive because we are still figuring out what the future of reviewing looks like. My default reaction is to read the code in this PR, but I don't think that's the right approach. Instead I need to interrogate this change with my own AI tools to run/add tests, run benchmarks, find other ways to reassure myself. We all need to get more comfortable working with PRs like this. We can't expect that comfort to happen overnight.

I think though that we'll need to get creative and change how we think about reviewing work.

I totally agree with this. The world has changed and we need to roll with it.

I would love for us to have a high-level discussion around this at the January community meeting dask/community#434. @mrocklin @dcherian @crusaderky as you've all been heavily engaged here I would love to see you there.

@mrocklin

mrocklin commented Jan 6, 2026 •

Copy link
Copy Markdown
Member Author

However, currently we are still on this journey to a well oiled AI coding ecosystem.

@jacobtomlinson it would be useful to have you weigh in on #12210

@mrocklin you've not done much reviewing lately so you may not be as burned as some of us are with the current pattern of novice contributors giving an issue link to claude, generating a poor quality PR and opening it for us to review. It's getting tiring.

I may not have done this recently, but I'm quite familiar with similar experiences and have nothing but empathy. I think it makes total sense to shut down low-ROI PRs quickly and without empathy.

However, this PR is not that. This is the result of a very senior engineer guiding an AI to implement something that is well designed. I'm really excited that this is what the future of development will look like.

Thank you so much for saying so. It's actually really important for me to hear that someone cares about this work. I appreciate these kind words Jacob. It's nice to receive some encouragement.

I would love for us to have a high-level discussion around this at the January community meeting dask/community#434. @mrocklin @dcherian @crusaderky as you've all been heavily engaged here I would love to see you there.

I would welcome a conversation with the people gathered here (and other people who have been reviewing work outside of this PR). I don't think that the community meeting is the place to do that. I think that the community meeting is more for the general public to come and talk about whatever they want to talk about. Maybe developers meet up before the community meeting? I'm around any time after 1:30pm UK time.

@jacobtomlinson

Copy link
Copy Markdown
Member

I don't think that the community meeting is the place to do that. I think that the community meeting is more for the general public to come and talk about whatever they want to talk about.

I think we should redefine what we mean by community meeting. For the last few years the general public haven't been coming along to talk about the things they want. Only the power-user/contributor/maintainer group have come together to discuss the project. I think this is good. We should have these conversations in a public space, spectators should be welcome, but speaking time should be proportional to that individual's effort spent improving the project. We should be more disciplined with enforcing this.

Under that definition of "community meeting" I think it's the perfect place to discuss this topic.

@mrocklin

mrocklin commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

We should have these conversations in a public space

I'm fine with that

but speaking time should be proportional to that individual's effort spent improving the project

Whose job will it be to set this expectation, and to enforce this? Historically I think I've found that I have to do this, and then I'm kind of painted as the bad guy, which I don't like. I've found this experience to be stressful and don't want to repeat it.

Also, if we are doing this at the community meeting is there a time within the community meeting that would make sense? I'd prefer to skip the other parts if possible (demos, etc.) but am happy to show up to talk about this topic.

@jacobtomlinson

jacobtomlinson commented Jan 6, 2026 •

Copy link
Copy Markdown
Member

Whose job will it be to set this expectation

We can update wording in the notes to set expectations and then rely on the czar (me this time) to enforce this.

I'd prefer to skip the other parts if possible

We have two short demos lined up this month, we can start with those and skip everything else. Then move on to this as the first agenda item.

@mrocklin

mrocklin commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

OK. I'll show up. I'm curious to see how things go.

@dcherian

dcherian commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

I have some family stuff scheduled around then. I will try my best to attend but might be 10-15minutes late.

@crusaderky

Copy link
Copy Markdown
Collaborator

Thank you so much for saying so. It's actually really important for me to hear that someone cares about this work.

I'd like to clarify: I really care about this work too. I strongly believe that array expressions are vital to keep dask.array relevant in the medium to long term. What I am against is having something so impactful and prone to regressions delivered in a format that no human can reasonably read.

I strongly agree that this needs a high-bandwidth call, with as many maintainers and stakeholders as possible present.

I would love for us to have a high-level discussion around this at the January community meeting dask/community#434. @mrocklin @dcherian @crusaderky as you've all been heavily engaged here I would love to see you there.

I will attend.

Whose job will it be to set this expectation, and to enforce this? Historically I think I've found that I have to do this, and then I'm kind of painted as the bad guy, which I don't like.

I've been wearing the cop hat at meetings before and I feel empathy. I think however that this kind of pivot deserves as much time as needed and I would not mind if the whole next community meeting was dominated by this discussion.

@mrocklin

mrocklin commented Jan 7, 2026

Copy link
Copy Markdown
Member Author

I'd like to clarify: I really care about this work too

Thank you for saying so @crusaderky . That means a lot. In the future I encourage you to lead interactions with similar statements. I think that otherwise you run the risk of demotivating people, and seeming somewhat toxic.

@mrocklin

mrocklin commented Jan 7, 2026

Copy link
Copy Markdown
Member Author

I chatted with @jacobtomlinson earlier today. Zooming out, my sense is that he's excited to talk about the use of AI in Dask, while I'm more interested in talking about whether or not Dask should take on array expressions.

The tension around array expressions is between helping Dask evolve and keeping Dask stable. I don't think that there's an obvious correct answer here. I'm excited about array expressions, but there's a very real chance that I work on this for a month, get it into a decent but not perfect state, and then move on to something else. Also, speaking personally, given all the pushback and drama on this PR, and given that no one other than me is speaking up for it, I don't really want to bother without more demand.

Given all of that, Jacob and I were thinking that maybe it's better if I go and build this elsewhere. Dask can be the stable thing while I go and work on the new thing. Totally open to other ideas, but that's where my head is at the moment.

Still though, "Dask and AI" is a great topic that I think you all should totally discuss. I got what I needed out of my chat with Jacob though so I'll leave you all to it (sometimes you all have nicer conversations without me around anyway, and the community meeting is not my favorite).

mrocklin added a commit to mrocklin/dask-array that referenced this pull request Jan 11, 2026
This code was brought over from dask/dask#12207

It is a full implementation of dask array with array expressions.

This branch has not been deployed

No deployments
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.

4 participants