BUG: numpy.ndarray.__deepcopy__ returned a result with an exception set
See original GitHub issueDescribe 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 https://github.com/python/cpython/issues/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)]
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Error: ...returned a result with an exception set - Stack Overflow
I was trying to copy an Object, which included a numpy array (which included other Objects(type "Feld")), with copy.deepcopy() and got this ...
Read more >numpy.copy — NumPy v1.24 Manual
Return an array copy of the given object. ... If True, then sub-classes will be passed-through, otherwise the returned array will be forced...
Read more >copy — Shallow and deep copy operations — Python 3.11.1 ...
This module provides generic shallow and deep copy operations (explained ... copy.deepcopy(x[, memo])¶. Return a deep copy of x. exception copy.Error¶.
Read more >jax.numpy package - JAX documentation - Read the Docs
Relatedly, some NumPy functions often return views of arrays when possible (examples are ... Test element-wise for NaN and return result as a...
Read more >SciPy 1.9.0 Release Notes — SciPy v1.9.3 Manual
nbinom.logcdf returns wrong results when some… #16426: BUG: stats.shapiro inplace modification of user array. #16446: BUG ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m at the Scipy sprints and will try taking a stab at this today
Yes, thought it would get auto-closed there, thanks.