Skip to content

Fix StopIteration crash in create_array with empty generator#99

Merged
cmutel merged 1 commit into
mainfrom
fix/create-array-empty-generator
Jun 4, 2026
Merged

Fix StopIteration crash in create_array with empty generator#99
cmutel merged 1 commit into
mainfrom
fix/create-array-empty-generator

Conversation

@cmutel

@cmutel cmutel commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

  • create_array crashed with StopIteration when passed an empty generator and no nrows, because get_ncols()peek()next() consumed the first element of an empty iterator with no guard
  • create_structured_array already handled this correctly by delegating directly to create_chunked_structured_array, which has an explicit empty-iterable fallback
  • Added a try/except StopIteration in the else-branch of create_array to return np.zeros((0, 0), dtype=dtype) when the iterator is empty

Closes #96.

Test plan

  • test_create_array_empty_generator_returns_empty_array — empty generator returns shape (0, 0) with default dtype
  • test_create_array_empty_generator_respects_dtype — dtype is preserved on the empty result
  • test_create_array_nonempty_generator — non-empty generator still produces correct shape and values (regression)

When no nrows is provided and the iterable has no __len__, create_array
called get_ncols() which consumed the first element via peek(). An empty
generator raised an unhandled StopIteration instead of returning a
zero-row array, unlike create_structured_array which handled this case.

Catches StopIteration in the else-branch and returns np.zeros((0, 0))
to match the documented empty-iterable contract. Closes #96.
@cmutel cmutel merged commit 8e0e088 into main Jun 4, 2026
6 checks passed
@cmutel cmutel deleted the fix/create-array-empty-generator branch June 4, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: create_array crashes with StopIteration on empty generator (no nrows)

1 participant