Skip to content

BUG: numpy.ndarray.__deepcopy__ returned a result with an exception set #21883

@mdickinson

Description

@mdickinson

Describe the issue:

It looks as though there's a code path in which ndarray.__deepcopy__ sets an exception but fails to return NULL, confusing Python as a result. This was reported upstream on the CPython bug tracker at python/cpython#94390, but looks as though it's likely a problem with NumPy.

#8706 looks relevant here. Specifically, I suspect that itemp is NULL in this call, resulting in the PyObject_CallFunctionObjArgs argument list being cut short.

I wasn't able to reproduce with an empty array of dtype object created directly with np.empty; it's not clear to me when such an array gets filled with NULLs and when it gets filled with pointers to Py_None.

Reproduce the code example:

import numpy as np
np.empty_like([slice(3)]).__deepcopy__({})

Error message:

TypeError: deepcopy() missing 1 required positional argument: 'x'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: <method '__deepcopy__' of 'numpy.ndarray' objects> returned a result with an exception set

NumPy/Python version information:

1.22.4 3.10.5 (main, Jun 7 2022, 08:51:33) [Clang 13.0.0 (clang-1300.0.29.30)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - BugsprintableIssue fits the time-frame and setting of a sprint

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions