question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 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:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jcusick13commented, Jul 16, 2022

I’m at the Scipy sprints and will try taking a stab at this today

0reactions
sebergcommented, Jul 21, 2022

Yes, thought it would get auto-closed there, thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found