Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: Fancy indexing with arrays of uint types fail on StringDType arrays #27710

Copy link
Copy link
Closed
@kolamp

Description

@kolamp
Issue body actions

Describe the issue:

When trying to index and array of type StringDType with an array of any unsigned integer type it fails returning a MemoryError (strangely):

MemoryError: Failed to load string in StringDType getitem
MemoryError: String deallocation failed in clear loop

It does work when the index array is cast to int.

Reproduce the code example:

import numpy as np
str_arr = np.array(["a" * 25], dtype=np.dtypes.StringDType())
idx = np.array([0], dtype=np.uint8)
print(str_arr[idx.astype(int)])
print(str_arr[idx])

Error message:

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    print(str_arr[idx])
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 1692, in _array_str_implementation
    return array2string(a, max_line_width, precision, suppress_small, ' ', "")
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 776, in array2string
    return _array2string(a, options, separator, prefix)
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 547, in wrapper
    return f(self, *args, **kwargs)
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 580, in _array2string
    lst = _formatArray(a, format_function, options['linewidth'],
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 935, in _formatArray
    return recurser(index=(),
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 896, in recurser
    word = recurser(index + (-1,), next_hanging_indent, next_width)
  File "lib/python3.10/site-packages/numpy/_core/arrayprint.py", line 839, in recurser
    return format_function(a[index])
MemoryError: Failed to load string in StringDType getitem
MemoryError: String deallocation failed in clear loop

Python and NumPy Versions:

Python: 3.10.6
Numpy: 2.1.3

Runtime Environment:

[{'numpy_version': '2.1.3',
'python': '3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:36:39) '
'[GCC 10.4.0]',
'uname': uname_result(system='Linux', node='...', release='5.15.133.1-microsoft-standard-WSL2', version='#1 SMP Thu Oct 5 21:02:42 UTC 2023', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL'],
'not_found': ['AVX512_KNL', 'AVX512_KNM']}},
{'architecture': 'SkylakeX',
'filepath': 'lib/python3.10/site-packages/numpy.libs/libscipy_openblas64_-ff651d7f.so',
'internal_api': 'openblas',
'num_threads': 16,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.27'}]

Context for the issue:

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.