Deduplicate chunked bucket-fill logic; fix #95 and #97 in the process#100
Merged
Conversation
create_chunked_structured_array and create_chunked_array shared identical bucket-fill loops that had to be maintained separately. Extract _fill_chunked, parameterised by bucket_shape and empty_shape, so both delegate to one place. The consolidation also fixes two latent bugs in the previous duplicate code: - create_chunked_array used np.hstack, which concatenates 2D arrays on axis=1 (columns) instead of axis=0 (rows), silently producing wrong shapes or raising ValueError for inputs longer than bucket_size rows. (#95) - The partial-chunk slice array[:i+1] was a view that kept the full bucket buffer alive until the final concatenation; now .copy() is called to release the oversized allocation immediately. (#97) Closes #98. Also fixes #95 and #97.
…create_chunked Both functions differed only in bucket shape; the _fill_chunked helper introduced in this branch already proved they were identical. Merge into a single public create_chunked that accepts an optional ncols parameter: omit for a 1D structured array, supply for a plain 2D array. Removes _fill_chunked, create_chunked_structured_array, and create_chunked_array entirely.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Collapses
create_chunked_structured_arrayandcreate_chunked_arrayinto a single publiccreate_chunkedfunction, and fixes two bugs that existed in the old implementations:create_chunked(iterable, dtype, ncols=None, bucket_size=500)handles both cases:ncols→ 1D structured arrayncols→ plain 2D array_fill_chunkedhelper) are removed entirely.Bugs fixed
create_chunked_arrayusednp.hstack, which for 2D arrays concatenates onaxis=1(columns) instead ofaxis=0(rows). Any input longer thanbucket_sizerows silently produced the wrong shape, or raisedValueErrorwhen a full and partial chunk were combined.create_chunkedusesnp.concatenate(arrays, axis=0), which is correct for both shapes.array[:i+1]was a NumPy view, keeping the full pre-allocated bucket buffer alive until the final concatenation.create_chunkedcalls.copy()on the slice to release the oversized allocation immediately.Closes #98. Also fixes #95 and #97.
Test plan
test_create_chunked_multiple_full_buckets— shape is(1000, 3), not(500, 6)test_create_chunked_full_plus_partial_bucket— noValueErrorwhen combining differently-sized chunkstest_create_chunked_under_one_bucket/test_create_chunked_empty_plaintest_create_chunked_structured_multiple_buckets/_under_one_bucket/_empty