Skip to content

Add support for slices in ChunkCachedArray - #2937

Merged
VeckoTheGecko merged 3 commits into
Parcels-code:mainfrom
VeckoTheGecko:push-uzxynxlsqyqn
Oct 6, 2026
Merged

VeckoTheGecko merged 3 commits into
Parcels-code:mainfrom
VeckoTheGecko:push-uzxynxlsqyqn

Conversation

@VeckoTheGecko

Copy link
Copy Markdown
Contributor

Description

This PR adds support for slicing in ChunkCachedArray

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.

    • I take responsibility for any AI-generated content in my PR.

    • Describe how you used it (e.g., by pasting your prompt):
      Used Claude Code (Claude Opus 5.5). I asked it to read TypeError in ChunkCachedArray: '<' not supported between instances of 'slice' and 'int' #2897 and write a minimal failing example. It traced the failure to the size-1 mockZ dimension, which _gather_corners leaves unindexed, so xarray hands ChunkCachedArray a slice(None). I then asked it to:

      • write a regression test (2D field with no depth, compared across backends against NumPy);
      • simplify the _vindex_get implementation, benchmark it, and find/remove code written on the assumption that slices aren't supported

      It also ran the test suite and Hypothesis checks with more examples.

Dimensions not given an indexer in .isel() (e.g. the size-1 mockZ
dimension for fields without depth) reach _vindex_get as slice(None),
which raised NotImplementedError. Expand each slice into an index array
over its own trailing dim, following vectorized indexing semantics, and
let _raw_vindex broadcast them against the integer indexers.

@erikvansebille erikvansebille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. One comment and one question below

Comment thread tests/test_backends.py
},
)
def test_field_without_depth_identical_across_backends(backend: BackendT):
"""Fields without a depth dimension get a size-1 ``mockZ`` dimension, which must

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we also check for mockT? Or will that be trivial?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think its worth expanding the test in this way, since we're fixing it fundamentally in the array API level

Comment on lines -162 to -167
if any(isinstance(k, slice) for k in key):
raise NotImplementedError(
"ChunkCachedArray does not support slices in vectorized indexers. "
"Use integer arrays for every dimension instead."
)
return self._raw_vindex(*key)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, so now slices are fine again. Nice

@VeckoTheGecko
VeckoTheGecko merged commit 3128851 into Parcels-code:main Oct 6, 2026
19 of 21 checks passed
@VeckoTheGecko

Copy link
Copy Markdown
Contributor Author

There was one test failure (one hypothesis case that was found a couple PRs ago, only affecting the minimum environment). I still need to find exactly why this failure is happening (it wasn't trivially reproducing) - but it shouldn't delay progress/release here.

@VeckoTheGecko
VeckoTheGecko deleted the push-uzxynxlsqyqn branch October 6, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TypeError in ChunkCachedArray: '<' not supported between instances of 'slice' and 'int'

2 participants