🌐 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/umath/string_ufuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ string_expandtabs_length_promoter(PyObject *NPY_UNUSED(ufunc),
PyArray_DTypeMeta *const op_dtypes[], PyArray_DTypeMeta *const signature[],
PyArray_DTypeMeta *new_op_dtypes[])
{
Py_INCREF(op_dtypes[0]);
Py_XINCREF(op_dtypes[0]);
new_op_dtypes[0] = op_dtypes[0];
new_op_dtypes[1] = NPY_DT_NewRef(&PyArray_Int64DType);
new_op_dtypes[2] = PyArray_DTypeFromTypeNum(NPY_DEFAULT_INT);
Expand Down
15 changes: 15 additions & 0 deletions numpy/_core/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import numpy as np
from numpy._core._exceptions import _UFuncNoLoopError
from numpy.testing import IS_PYPY, assert_array_equal, assert_raises
from numpy.testing._private.utils import requires_memory

Expand Down Expand Up @@ -821,6 +822,20 @@ def test_expandtabs_raises_overflow(self, dt):
np.strings.expandtabs(np.array("\ta\n\tb", dtype=dt), sys.maxsize)
np.strings.expandtabs(np.array("\ta\n\tb", dtype=dt), 2**61)

def test_expandtabs_length_not_cause_segfault(self, dt):
# see gh-28829
with pytest.raises(
_UFuncNoLoopError,
match="did not contain a loop with signature matching types",
):
np._core.strings._expandtabs_length.reduce(np.zeros(200))

with pytest.raises(
_UFuncNoLoopError,
match="did not contain a loop with signature matching types",
):
np.strings.expandtabs(np.zeros(200))

FILL_ERROR = "The fill character must be exactly one character long"

def test_center_raises_multiple_character_fill(self, dt):
Expand Down
Loading