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

Commit0cb5982

Browse files
committed
BUG: ensure passingnp.dtype to itself doesn't crash
1 parent2f34979 commit0cb5982

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,11 @@ PyArray_DTypeOrDescrConverterRequired(PyObject *obj, npy_dtype_info *dt_info)
14791479
dt_info->descr=NULL;
14801480

14811481
if (PyObject_TypeCheck(obj,&PyArrayDTypeMeta_Type)) {
1482+
if (obj== (PyObject*)&PyArrayDescr_Type) {
1483+
PyErr_SetString(PyExc_TypeError,
1484+
"Cannot convert np.dtype into a dtype.");
1485+
returnNPY_FAIL;
1486+
}
14821487
Py_INCREF(obj);
14831488
dt_info->dtype= (PyArray_DTypeMeta*)obj;
14841489
dt_info->descr=NULL;

‎numpy/_core/tests/test_dtype.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,3 +1931,9 @@ def test_result_type_integers_and_unitless_timedelta64():
19311931
td=np.timedelta64(4)
19321932
result=np.result_type(0,td)
19331933
assert_dtype_equal(result,td.dtype)
1934+
1935+
1936+
deftest_creating_dtype_with_dtype_class_errors():
1937+
# Regression test for #25031, calling `np.dtype` with itself segfaulted.
1938+
withpytest.raises(TypeError,match="Cannot convert np.dtype into a dtype"):
1939+
np.array(np.ones(10),dtype=np.dtype)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp