Skip to content

BUG: np.fromiter creates corrupted arrays when re-using StringDType instance #32013

Closed

Description

@Yeshwanth-G

Describe the issue:

When re-using the StringDType instance, np.fromiter creates corrupted arrays leading to flaky failures.

Reproduce the code example:

Reproducer:

>>> np.__version__
'2.5.0'

>>> sd = np.dtypes.StringDType()

>>> a = ["a"*18, "b"*18]*10_000

>>> np.fromiter(iter(a), dtype=sd, count=len(a))
array(['aaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaa',
       ..., 'bbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaa',
       'bbbbbbbbbbbbbbbbbb'], shape=(20000,), dtype=StringDType())

>>> np.fromiter(iter(a), dtype=sd, count=len(a)) # same snippet ran for the second time segfaults.
Fatal Python error: Segmentation fault

Python and NumPy Versions:

import sys, numpy; print(numpy.version); print(sys.version)
2.5.0
3.14.4

Activity

  1. changed the title [-]BUG: np.fromiter creates corrupted arrays when re-using StringDType instance[/-] [+]BUG: `np.fromiter` creates corrupted arrays when re-using StringDType instance[/+] on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions