| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,7 @@ | |||
| 1 | 1 | * UFuncs now support ``__dict__`` attribute and allow overriding ``__doc__`` | |
| 2 | 2 | (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. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,8 +133,8 @@ PyMODINIT_FUNC PyInit__struct_ufunc_tests(void) | |||
| 133 | 133 | import_umath(); | |
| 134 | 134 | ||
| 135 | 135 | 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); | ||
| 138 | 138 | ||
| 139 | 139 | dtype_dict = Py_BuildValue("[(s, s), (s, s), (s, s)]", | |
| 140 | 140 | "f0", "u8", "f1", "u8", "f2", "u8"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,6 +167,13 @@ ufunc_frompyfunc(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds) { | |||
| 167 | 167 | PyObject * | |
| 168 | 168 | add_newdoc_ufunc(PyObject *NPY_UNUSED(dummy), PyObject *args) | |
| 169 | 169 | { | |
| 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 | + | ||
| 170 | 177 | PyUFuncObject *ufunc; | |
| 171 | 178 | PyObject *str; | |
| 172 | 179 | if (!PyArg_ParseTuple(args, "O!O!:_add_newdoc_ufunc", &PyUFunc_Type, &ufunc, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | ) | |
| 16 | 16 | ||
| 17 | 17 | from numpy._core._multiarray_tests import fromstring_null_term_c_api | |
| 18 | + import numpy._core._struct_ufunc_tests as struct_ufunc | ||
| 18 | 19 | ||
| 19 | 20 | try: | |
| 20 | 21 | import pytz | |
@@ -732,3 +733,13 @@ def test_deprecated(self): | |||
| 732 | 733 | self.assert_deprecated(np.save, args=sample_args, | |
| 733 | 734 | kwargs={'allow_pickle': allow_pickle, | |
| 734 | 735 | '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 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4884,9 +4884,11 @@ def func(): | |||
| 4884 | 4884 | ||
| 4885 | 4885 | ||
| 4886 | 4886 | class TestAdd_newdoc_ufunc: | |
| 4887 | + @pytest.mark.filterwarnings("ignore:_add_newdoc_ufunc:DeprecationWarning") | ||
| 4887 | 4888 | def test_ufunc_arg(self): | |
| 4888 | 4889 | assert_raises(TypeError, ncu._add_newdoc_ufunc, 2, "blah") | |
| 4889 | 4890 | assert_raises(ValueError, ncu._add_newdoc_ufunc, np.add, "blah") | |
| 4890 | 4891 | ||
| 4892 | + @pytest.mark.filterwarnings("ignore:_add_newdoc_ufunc:DeprecationWarning") | ||
| 4891 | 4893 | def test_string_arg(self): | |
| 4892 | 4894 | assert_raises(TypeError, ncu._add_newdoc_ufunc, np.add, 3) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments