Skip to content

BUG: ndarray.resize() recheck argument sometimes causes incorrect ValueError with Python 3.14 #30991

@rpmcnally

Description

@rpmcnally

Describe the issue:

I'm building Python 3.14.3 from scratch on a RHEL 8 workstation with GCC 12.2 and installing numpy 2.4.3 through PIP. Simply trying to execute the example code in the ndarray.resize() documentation leads to a value error.

This seems related to #30278.

It appears that I'm still getting an additional reference count coming down the call stack and the new method being used (PyUnstable_Object_IsUniquelyReferenced()) is claiming it isn't unique, though I have not modified the numpy source to verify this is the case.

I'm building Python with:

installPrefix=/path/to/python
./configure --libdir=$installPrefix/Python-3.14.3/lib \
            --enable-shared \
            --enable-optimizations --with-lto \
            --prefix=$installPrefix/Python-3.14.3

Reproduce the code example:

import numpy as np
a = np.array([[0, 1], [2, 3]], order='C')
a.resize((2, 1))

Error message:

Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    a.resize((2, 1))
    ~~~~~~~~^^^^^^^^
ValueError: cannot resize an array that references or is referenced
by another array in this way.
Use the np.resize function or refcheck=False

Python and NumPy Versions:

2.4.3
3.14.3 (main, Mar 11 2026, 15:21:20) [GCC 12.2.0]

Runtime Environment:

[{'numpy_version': '2.4.3',
'python': '3.14.3 (main, Mar 11 2026, 15:21:20) [GCC 12.2.0]',
'uname': uname_result(system='Linux', node='calvin.create.hpc.mil', release='4.18.0-553.104.1.el8_10.x86_64', version='#1 SMP Tue Feb 3 13:44:58 EST 2026', machine='x86_64')},
{'simd_extensions': {'baseline': ['X86_V2'],
'found': ['X86_V3', 'X86_V4'],
'not_found': ['AVX512_ICL', 'AVX512_SPR']}},
{'ignore_floating_point_errors_in_matmul': False},
{'architecture': 'SkylakeX',
'filepath': '/home/mcnally/Development/ptoolsrte/0.7.0/packages/Python-3.14.3/lib/python3.14/site-packages/numpy.libs/libscipy_openblas64_-ff84a88b.so',
'internal_api': 'openblas',
'num_threads': 64,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.31.dev'}]

How does this issue affect you or how did you find it:

Quite a bit of code that previously worked fine now generates errors. This was found when upgrading our dependency stack to the Python and numpy versions listed above. We were previously on Python 3.9 and numpy 1.25.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions