Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit58be8c9

Browse files
authored
Merge pull request#28654 from charris/backport-28643
BUG: fix deepcopying StringDType arrays (#28643)
2 parentsbac7b36 +3c83161 commit58be8c9

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

‎numpy/_core/src/multiarray/methods.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype,
16051605
}
16061606
}
16071607
}
1608-
else {
1608+
elseif (PyDataType_ISOBJECT(dtype)){
16091609
PyObject*itemp,*otemp;
16101610
PyObject*res;
16111611
memcpy(&itemp,iptr,sizeof(itemp));

‎numpy/_core/tests/test_stringdtype.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
importconcurrent.futures
2+
importcopy
23
importitertools
34
importos
4-
importpickle
55
importstring
6+
importpickle
67
importsys
78
importtempfile
89

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

407408

409+
deftest_stdlib_copy(dtype,string_list):
410+
arr=np.array(string_list,dtype=dtype)
411+
412+
assert_array_equal(copy.copy(arr),arr)
413+
assert_array_equal(copy.deepcopy(arr),arr)
414+
415+
408416
@pytest.mark.parametrize(
409417
"strings",
410418
[
@@ -1728,12 +1736,12 @@ def test_zeros(self):
17281736
assert_array_equal(z,"")
17291737

17301738
deftest_copy(self):
1731-
c=self.a.copy()
1732-
assert_array_equal(self.get_flags(c),self.get_flags(self.a))
1733-
assert_array_equal(c,self.a)
1734-
offsets=self.get_view(c)['offset']
1735-
assertoffsets[2]==1
1736-
assertoffsets[3]==1+len(self.s_medium)+self.sizeofstr//2
1739+
forcin [self.a.copy(),copy.copy(self.a),copy.deepcopy(self.a)]:
1740+
assert_array_equal(self.get_flags(c),self.get_flags(self.a))
1741+
assert_array_equal(c,self.a)
1742+
offsets=self.get_view(c)['offset']
1743+
assertoffsets[2]==1
1744+
assertoffsets[3]==1+len(self.s_medium)+self.sizeofstr//2
17371745

17381746
deftest_arena_use_with_setting(self):
17391747
c=np.zeros_like(self.a)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp