Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: fix deepcopying StringDType arrays (#28643) #28654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
BUG: fix deepcopying StringDType arrays (#28643)
Fixes #28609
  • Loading branch information
ngoldbaum authored and charris committed Apr 5, 2025
commit 3c831617b5778038613c9f9d1672948e534815f9
2 changes: 1 addition & 1 deletion 2 numpy/_core/src/multiarray/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype,
}
}
}
else {
else if (PyDataType_ISOBJECT(dtype)) {
PyObject *itemp, *otemp;
PyObject *res;
memcpy(&itemp, iptr, sizeof(itemp));
Expand Down
22 changes: 15 additions & 7 deletions 22 numpy/_core/tests/test_stringdtype.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import concurrent.futures
import copy
import itertools
import os
import pickle
import string
import pickle
import sys
import tempfile

Expand Down Expand Up @@ -405,6 +406,13 @@ def test_pickle(dtype, string_list):
os.remove(f.name)


def test_stdlib_copy(dtype, string_list):
arr = np.array(string_list, dtype=dtype)

assert_array_equal(copy.copy(arr), arr)
assert_array_equal(copy.deepcopy(arr), arr)


@pytest.mark.parametrize(
"strings",
[
Expand Down Expand Up @@ -1728,12 +1736,12 @@ def test_zeros(self):
assert_array_equal(z, "")

def test_copy(self):
c = self.a.copy()
assert_array_equal(self.get_flags(c), self.get_flags(self.a))
assert_array_equal(c, self.a)
offsets = self.get_view(c)['offset']
assert offsets[2] == 1
assert offsets[3] == 1 + len(self.s_medium) + self.sizeofstr // 2
for c in [self.a.copy(), copy.copy(self.a), copy.deepcopy(self.a)]:
assert_array_equal(self.get_flags(c), self.get_flags(self.a))
assert_array_equal(c, self.a)
offsets = self.get_view(c)['offset']
assert offsets[2] == 1
assert offsets[3] == 1 + len(self.s_medium) + self.sizeofstr // 2

def test_arena_use_with_setting(self):
c = np.zeros_like(self.a)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.