Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
correct signature and type check
  • Loading branch information
eendebakpt committed Sep 2, 2025
commit 6b47b9871a4dbdd6c229f61d3ea553c4aed8303c
14 changes: 8 additions & 6 deletions numpy/_core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -2108,25 +2108,27 @@ gentype_@name@(PyObject *self, PyObject *args)
/**end repeat**/

static PyObject *
gentype___copy__(PyObject *self)
gentype___copy__(PyObject *self, PyObject *args)
{
// scalars are immutable, so we can return a new reference
// the only expections are scalars with void dtype
if PyObject_IsInstance(obj, (PyObject *)&PyVoidScalarObject)) {
if (PyObject_IsInstance(self, (PyObject *)&PyVoidArrType_Type)) {
// path via array
return gentype_generic_method(self, NULL, NULL, "__copy__");
return gentype_generic_method(self, args, NULL, "__copy__");
}
return Py_NewRef(self);
}

static PyObject *
gentype___deepcopy__(PyObject *self)
gentype___deepcopy__(PyObject *self, PyObject *args)
{
// note: maybe the signature needs to be updated as __deepcopy__ can accept the keyword memo

// scalars are immutable, so we can return a new reference
// the only expections are scalars with void dtype
if PyObject_IsInstance(obj, (PyObject *)&PyVoidScalarObject)) {
if (PyObject_IsInstance(self, (PyObject *)&PyVoidArrType_Type)) {
// path via array
return gentype_generic_method(self, NULL, NULL, "__deepcopy__");
return gentype_generic_method(self, args, NULL, "__deepcopy__");
}
return Py_NewRef(self);
}
Expand Down
7 changes: 7 additions & 0 deletions numpy/_core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,13 @@ def test__deepcopy__(self, dtype):
with pytest.raises(AssertionError):
assert_array_equal(a, b)

def test__deepcopy___void_scalar(self):
# gh-xxxx
v = np.void('Rex', dtype=[('name', 'U10') ])
w = v.__deepcopy__(None)
v[0]=None
assert w[0] == 'Rex'

def test__deepcopy__catches_failure(self):
class MyObj:
def __deepcopy__(self, *args, **kwargs):
Expand Down
Loading