Skip to content

feat(python): add ChunkedArray.from_chunks - #11620

Open
robert3005 wants to merge 1 commit into
developfrom
rk/python-chunked-from-chunks
Open

robert3005 wants to merge 1 commit into
developfrom
rk/python-chunked-from-chunks

Conversation

@robert3005

@robert3005 robert3005 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Python had no way to combine Vortex arrays into a chunked array. A reader of
several files, such as a map-style dataset of training samples, made one take
for each file that a batch touched, then concatenated the parts and put the
rows back in the order of the request.

ChunkedArray.from_chunks(chunks, *, dtype=None) combines arrays of one dtype
with no copy. The chunks of a chunked input become chunks of the result, so
the result has one level of chunks. The arrays that read_all gives for the
files then combine into one array, and one take reads a batch of rows in any
order from all the files.

@robert3005 robert3005 added the changelog/feature A new feature label Nov 22, 2026
@lwwmanning

Copy link
Copy Markdown
Contributor

Posted by Claude Opus 5.5 on Will's behalf.

Closing this as superseded by #11696, which has merged. The use case here was one take of a batch of rows, in any order, across several files. vortex.open_dataset now opens the files as one VortexDataset, and its take reads rows across files, so a reader no longer needs to combine per-file arrays with ChunkedArray.from_chunks.

@lwwmanning lwwmanning closed this Nov 23, 2026
@robert3005 robert3005 reopened this Nov 23, 2026
@robert3005

Copy link
Copy Markdown
Contributor Author

This pr is not superseeded by other changes. This is to allow combining in arrays that are already already in memory into chunked array, rescanning the file is not a replacement

@robert3005
robert3005 marked this pull request as ready for review November 23, 2026 21:38
@robert3005
robert3005 enabled auto-merge (squash) November 23, 2026 21:40
Python had no way to combine Vortex arrays into a chunked array. A reader of
several files, such as a map-style dataset of training samples, made one take
for each file that a batch touched, then concatenated the parts and put the
rows back in the order of the request.

`ChunkedArray.from_chunks(chunks, *, dtype=None)` combines arrays of one dtype
with no copy. The chunks of a chunked input become chunks of the result, so
the result has one level of chunks. The arrays that `read_all` gives for the
files then combine into one array, and one take reads a batch of rows in any
order from all the files.
@robert3005
robert3005 force-pushed the rk/python-chunked-from-chunks branch from 2ab9724 to b024766 Compare November 23, 2026 21:45

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Posted by Claude Opus 5.5 on Will's behalf.

Fair point, I closed this too quickly. #11696 covers arrays that come from files, but not arrays a caller already holds in memory, such as results from several sources or from earlier reads.

The code looks right. It flattens one level of chunks, takes the dtype from the first chunk or from dtype, and ChunkedArray::try_new rejects mismatched chunks. Three small points:

  1. try_new compares dtypes exactly, nullability included, so a nullable and a non-nullable array of the same type cannot be combined. Is that intended for the Python API, or should it accept chunks that differ only in nullability?
  2. The description still gives the read_all use case, which #11696 now covers. The in-memory case from your comment is the better reason to state there.
  3. The mixed-dtype test uses pytest.raises(Exception) (inline).



def test_chunked_array_from_chunks_rejects_mixed_dtypes() -> None:
with pytest.raises(Exception):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pytest.raises(Exception) passes for any failure, including a bug in argument handling. Matching the specific error, for example with match="expected type", would show that the dtype check is what rejects it.

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

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants