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

Appearance settings

Commit aa8f033

Browse filesBrowse files
committed
Deprecated _add_newdoc_ufunc
1 parent 60fb218 commit aa8f033
Copy full SHA for aa8f033

File tree

Expand file treeCollapse file tree

5 files changed

+25
-3
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+25
-3
lines changed
+5-1Lines 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

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/_struct_ufunc_tests.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/umathmodule.c
+7Lines 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

Copy file name to clipboardExpand all lines: numpy/_core/tests/test_deprecations.py
+9Lines changed: 9 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,11 @@ 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(struct_ufunc.add_triplet, "new docs")
743+
)

‎numpy/_core/tests/test_umath.py

Copy file name to clipboardExpand all lines: numpy/_core/tests/test_umath.py
+2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.