Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Structured dtype patching might affect no field location #29720

@ZisIsNotZis

Description

@ZisIsNotZis

Describe the issue:

I was trying to "patch" a structed array (contiguous) with a structed patch array (non contiguous). It turns out that if I use a.view(b.dtype)[0]=b, the result is more or less random, while if I use a.view(b.dtype)[:1]=b, then things works

Reproduce the code example:

import numpy as np
a = np.array([False,False],'?,?,?,?')
b = np.array(True,{'names':['f1'],'formats':['?'],'offsets':[1],'itemsize':4})
a.view(b.dtype)[0] = b
print(a)

Error message:

When I try multiple times in REPL, it's cycling between

[( True,  True, False, False) (False, False, False, False)] # Wrong

and

[(False,  True, False, False) (False, False, False, False)] # Correct

Python and NumPy Versions:

2.3.2
3.12.11 (main, Aug 8 2025, 17:06:48) [Clang 20.1.4 ]

Runtime Environment:

[{'numpy_version': '2.3.2',
'python': '3.12.11 (main, Aug 8 2025, 17:06:48) [Clang 20.1.4 ]',
'uname': uname_result(system='Linux', node='z', release='6.17.0-3-generic', version='#3-Ubuntu SMP PREEMPT_DYNAMIC Thu Aug 28 10:21:42 UTC 2025', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'architecture': 'Haswell',
'filepath': '/home/z/.venv/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so',
'internal_api': 'openblas',
'num_threads': 12,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.30'}]

Context for the issue:

Because it's expected not to affect no-element position for sparse strutured array

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