Skip to content

fix: support mixed slice indexing in ChunkCachedArray - #2911

Closed
mvanhorn wants to merge 2 commits into
Parcels-code:mainfrom
mvanhorn:fix/2897-chunk-cached-array-slice-indexing
Closed

mvanhorn wants to merge 2 commits into
Parcels-code:mainfrom
mvanhorn:fix/2897-chunk-cached-array-slice-indexing

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Sep 28, 2026 •

Copy link
Copy Markdown

Description

Fixes ChunkCachedArray._vindex_get for mixed vectorized keys (integer arrays plus slices), which xarray produces when some dimensions are indexed and others are left whole.

A Delft3D surface field loaded with to_chunk_cached_arrays() failed in _gather_corners: the array is (time, mockZ, N, M) with a singleton mockZ, time/N/M are indexed, and mockZ is left as slice(None). _raw_vindex treated that slice as a 1-D integer array during negative-index normalization. The same simulation works with windowed arrays, so this is local to the cache backend.

Changes, all in _vindex_get:

  • Broadcast the integer index arrays to a common shape and expand each slice with slice.indices for its dimension.
  • Order the slice axes after the broadcast index axes, matching xarray's vectorized-indexing order. Then flatten into per-dimension coordinates for the existing chunk-grouping _raw_vindex, and reshape the result.
  • Keep the existing fast path for equal-length 1-D all-array keys.
  • Return early for zero-point selections, and raise IndexError for integer indices out of range before chunk lookup. Valid negative indices still work.

The per-chunk LRU fetch path is unchanged. The bug reproduces with synthetic arrays, so the tests don't need the reporter's data.

Closes #2897

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.

I used AI assistance to write the fix and tests. tests/test_chunk_cached_array.py and tests/test_interpolation.py pass locally (59 passed, Python 3.13).

@VeckoTheGecko

Copy link
Copy Markdown
Contributor

Hi @mvanhorn . Can you please complete the AI disclosure part of the PR template? We want to make sure all PRs submitted to our project have a human behind the wheel.

@mvanhorn

Copy link
Copy Markdown
Author

Done, the AI disclosure section is filled in. I used AI assistance for the fix and tests, reviewed them, and ran test_chunk_cached_array.py and test_interpolation.py locally (59 passed). I also dropped a uv.lock that had slipped into the branch.

@VeckoTheGecko

Copy link
Copy Markdown
Contributor

superceded by #2921

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