Skip to content

Commit a507bf6

Browse files
committed
Deprecated _add_newdoc_ufunc
1 parent 60fb218 commit a507bf6

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
* UFuncs now support ``__dict__`` attribute and allow overriding ``__doc__``
22
(either directly or via ``ufunc.__dict__["__doc__"]``). ``__dict__`` can be
3-
used to also override other properties, such as ``__module__`` or ``__qualname__``.
3+
used to also override other properties, such as ``__module__`` or
4+
``__qualname__``.
5+
6+
* ``_add_newdoc_ufunc`` is now deprecated. ``ufunc.__doc__ = newdoc`` should
7+
be used instead.

numpy/_core/src/umath/_struct_ufunc_tests.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ PyMODINIT_FUNC PyInit__struct_ufunc_tests(void)
133133
import_umath();
134134

135135
add_triplet = PyUFunc_FromFuncAndData(NULL, NULL, NULL, 0, 2, 1,
136-
PyUFunc_None, "add_triplet",
137-
"add_triplet_docstring", 0);
136+
PyUFunc_None, "add_triplet",
137+
NULL, 0);
138138

139139
dtype_dict = Py_BuildValue("[(s, s), (s, s), (s, s)]",
140140
"f0", "u8", "f1", "u8", "f2", "u8");

numpy/_core/src/umath/umathmodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ ufunc_frompyfunc(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds) {
167167
PyObject *
168168
add_newdoc_ufunc(PyObject *NPY_UNUSED(dummy), PyObject *args)
169169
{
170+
171+
/* 2024-11-12, NumPy 2.2 */
172+
if (DEPRECATE("_add_newdoc_ufunc is deprecated. "
173+
"Use `ufunc.__doc__ = newdoc` instead.") < 0) {
174+
return NULL;
175+
}
176+
170177
PyUFuncObject *ufunc;
171178
PyObject *str;
172179
if (!PyArg_ParseTuple(args, "O!O!:_add_newdoc_ufunc", &PyUFunc_Type, &ufunc,

numpy/_core/tests/test_deprecations.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616

1717
from numpy._core._multiarray_tests import fromstring_null_term_c_api
18+
import numpy._core._struct_ufunc_tests as struct_ufunc
1819

1920
try:
2021
import pytz
@@ -732,3 +733,13 @@ def test_deprecated(self):
732733
self.assert_deprecated(np.save, args=sample_args,
733734
kwargs={'allow_pickle': allow_pickle,
734735
'fix_imports': False})
736+
737+
738+
class TestAddNewdocUFunc(_DeprecationTestCase):
739+
# Deprecated in Numpy 2.2, 2024-11
740+
def test_deprecated(self):
741+
self.assert_deprecated(
742+
lambda: np._core.umath._add_newdoc_ufunc(
743+
struct_ufunc.add_triplet, "new docs"
744+
)
745+
)

numpy/_core/tests/test_umath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4884,9 +4884,11 @@ def func():
48844884

48854885

48864886
class TestAdd_newdoc_ufunc:
4887+
@pytest.mark.filterwarnings("ignore:_add_newdoc_ufunc:DeprecationWarning")
48874888
def test_ufunc_arg(self):
48884889
assert_raises(TypeError, ncu._add_newdoc_ufunc, 2, "blah")
48894890
assert_raises(ValueError, ncu._add_newdoc_ufunc, np.add, "blah")
48904891

4892+
@pytest.mark.filterwarnings("ignore:_add_newdoc_ufunc:DeprecationWarning")
48914893
def test_string_arg(self):
48924894
assert_raises(TypeError, ncu._add_newdoc_ufunc, np.add, 3)

0 commit comments

Comments
 (0)