Skip to content

feat: support broadcast integer-array indexing for COO - #1026

Merged
hameerabbasi merged 1 commit into
pydata:mainfrom
FFspiky:feat/coo-broadcast-integer-indexing
Nov 11, 2026
Merged

hameerabbasi merged 1 commit into
pydata:mainfrom
FFspiky:feat/coo-broadcast-integer-indexing

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • 🪄 Feature
  • 🐞 Bug Fix
  • 🔧 Optimization
  • 📚 Documentation
  • 🧪 Test
  • 🛠️ Other

Related issues

Related to #114. This implements dense integer-array retrieval for COO; sparse integer indexers and assignment remain unsupported, so it does not close the whole issue.

Checklist

  • Code follows style guide
  • Tests added
  • Documented the changes

Please explain your changes below.

COO currently rejects multidimensional integer indexers and singleton broadcasting between index arrays. For example, selecting a (3, 4) array with two (2, 2) integer indexers raises IndexError instead of returning the NumPy-equivalent (2, 2) result.

Count each integer array as one consumed source axis, broadcast the indexers, and flatten them for the existing Numba selection kernels. Reconstruct coordinates in the broadcast shape and move the entire advanced-index dimension block when it is separated by basic indices. Preserve fill values, scalar/array distinctions, empty results, and source sparsity. Also restrict the multi-array kernel to axes retained after pruning full trailing slices; the previous loop can access beyond its index buffers with Numba bounds checking enabled.

Tests cover negative/repeated/mixed-width integers, singleton broadcasting, zero-dimensional and empty indexers, slices, new axes, ellipses, invalid shapes/bounds, and source immutability. A (10**11, 2) sparse source is indexed while COO.todense is patched to fail. The documentation describes the supported COO behavior and remaining limits. Sparse boolean masks in #962 and GCXS axis placement in #990 are separate changes.

Validation on macOS arm64, Python 3.12.14, NumPy 2.5.4 and Numba 0.68.1:

  • Full Numba backend suite: 6,894 passed, 117 xfailed, 37 xpassed, no failures. Existing non-strict xfail marks were not changed.
  • Affected indexing suite with NUMBA_BOUNDSCHECK=1: 167 passed.
  • 14 module doctests and 5,300 fixed-seed NumPy differential cases passed.
  • Repository pre-commit hooks and git diff --check passed.

Finch/MLIR, the external Array API suite, other platforms, and a documentation build were not run locally. Index buffers may allocate space proportional to the broadcast index shape; the source stays sparse. No performance improvement is claimed, and Array API capability flags/xfails are unchanged.

AI assistance: OpenAI Codex implemented the changes, ran the checks, and drafted this description.

Broadcast dense index arrays, reconstruct result coordinates and preserve NumPy advanced-axis placement. Bound the selection kernel to retained axes after pruning.

Refs pydata#114.

Assisted-by: Codex
@github-actions github-actions Bot added the enhancement Indicates new feature requests label Nov 11, 2026
@hameerabbasi
hameerabbasi merged commit e7d4131 into pydata:main Nov 11, 2026
12 of 14 checks passed
@Eliot5566 Eliot5566 mentioned this pull request Nov 12, 2026
4 of 10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Indicates new feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants