From b4b790a970a845415f34d6d65c79a72624674533 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Tue, 9 Apr 2024 09:05:49 -0400 Subject: [PATCH] Update import of add_newdoc_ufunc for Numpy 2.0.0 The funcion `add_newdoc_ufunc` is no longer part of the Numpy public API, although according to upstream developers it is not going away any time soon. See https://github.com/numpy/numpy/issues/26233. --- ligo/skymap/util/numpy.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ligo/skymap/util/numpy.py b/ligo/skymap/util/numpy.py index eeeccc27..1afb91b5 100644 --- a/ligo/skymap/util/numpy.py +++ b/ligo/skymap/util/numpy.py @@ -16,17 +16,28 @@ # import functools import numpy as np +from numpy.core.umath import _add_newdoc_ufunc __all__ = ('add_newdoc_ufunc', 'require_contiguous_aligned') def add_newdoc_ufunc(func, doc): # pragma: no cover - """The function `np.lib.add_newdoc_ufunc` can only change a ufunc's - docstring if it is `NULL`. This workaround avoids an exception when the - user tries to `reload()` this module. + """Set the docstring for a Numpy ufunc. + + The function :func:`numpy.core.umath._add_newdoc_ufunc` can only change a + ufunc's docstring if it is `NULL`. This workaround avoids an exception when + the user tries to `reload()` this module. + + Notes + ----- + :func:`numpy.core.umath._add_newdoc_ufunc` is not part of Numpy's public + API, but according to upstream developers it is unlikely to go away any + time soon. + + See https://github.com/numpy/numpy/issues/26233. """ try: - np.lib.add_newdoc_ufunc(func, doc) + _add_newdoc_ufunc(func, doc) except ValueError as e: msg = 'Cannot change docstring of ufunc with non-NULL docstring' if e.args[0] == msg: