🌐 AI搜索 & 代理 主页
Skip to content
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
2 changes: 1 addition & 1 deletion numpy/_core/src/multiarray/stringdtype/static_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ heap_or_arena_allocate(npy_string_allocator *allocator,
if (*flags == 0) {
// string isn't previously allocated, so add to existing arena allocation
char *ret = arena_malloc(arena, allocator->realloc, sizeof(char) * size);
if (size < NPY_MEDIUM_STRING_MAX_SIZE) {
if (size <= NPY_MEDIUM_STRING_MAX_SIZE) {
*flags = NPY_STRING_INITIALIZED;
}
else {
Expand Down
18 changes: 18 additions & 0 deletions numpy/_core/tests/test_stringdtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,24 @@ def test_growing_strings(dtype):
assert_array_equal(arr, uarr)


def test_assign_medium_strings():
# see gh-29261
N = 9
src = np.array(
(
['0' * 256] * 3 + ['0' * 255] + ['0' * 256] + ['0' * 255] +
['0' * 256] * 2 + ['0' * 255]
), dtype='T')
dst = np.array(
(
['0' * 255] + ['0' * 256] * 2 + ['0' * 255] + ['0' * 256] +
['0' * 255] + [''] * 5
), dtype='T')

dst[1:N + 1] = src
assert_array_equal(dst[1:N + 1], src)


UFUNC_TEST_DATA = [
"hello" * 10,
"Ae¢☃€ 😊" * 20,
Expand Down
Loading