Repository navigation
Fix ufunc docstrings showing the C macro name - #282
Open
antonwolfy wants to merge 3 commits into
Open
antonwolfy wants to merge 3 commits into
antonwolfy wants to merge 3 commits into
Conversation
antonwolfy
requested review from
jharlow-intel,
ndgrigorian,
vlad-perevezentsev and
xaleryb
as code owners
October 14, 2026 12:06
jharlow-intel
previously approved these changes
Oct 15, 2026
jharlow-intel
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, this is a nice fix! Fixing it in the generator means every ufunc gets a real docstring under both NumPy 1 and 2, and the new parametrized test will keep it that way. Just one small changelog note inline.
Since the NumPy 2.x alignment (gh-65), generate_umath.py emits each docstring as a DOC_* macro name, as NumPy does, but kept it quoted and the header defining those macros was never generated. Every ufunc __doc__ therefore ended with the literal macro name, e.g. DOC_NUMPY__CORE_UMATH_SIN, instead of the docstring text. - meson.build: generate _umath_doc_generated.h with generate_umath_doc.py and add it to the _ufuncs sources - generate_umath.py: emit the macro unquoted and include the header in the generated code, matching upstream NumPy - test_basic.py: check every ufunc docstring is expanded
antonwolfy
force-pushed
the
fix-ufunc-docstrings
branch
from
October 15, 2026 17:51
b4538a7 to
d5ada92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
__doc__of everymkl_umathufunc, which ended with a literal C macro name instead of the docstring text:All 58 public ufuncs were affected, in every release since 0.3.0. NumPy's own ufuncs are not affected by patching, since
patch_numpy_umath()swaps loops, not ufunc objects.Root cause
gh-65 aligned
generate_umath.pywith NumPy 2.2's docstring scheme:docstrings.get()returns the name of aDOC_*C macro, defined in a_umath_doc_generated.hheader produced bygenerate_umath_doc.py. Two pieces of that scheme were not carried over:"{doc}"), a leftover from the previous scheme where it held the docstring text itself, so the C code got the string"DOC_NUMPY__CORE_UMATH_SIN";generate_umath_doc.pywas ported but never invoked by the build, so the header defining the macros was neither generated nor included.Fix
meson.build: add acustom_targetthat generates_umath_doc_generated.h(rerun whenufunc_docstrings_numpy{1,2}.pychange) and add it to the_ufuncssources.generate_umath.py: emit the macro unquoted and#include "_umath_doc_generated.h"in the generated code, matching upstream NumPy. The obsolete "difference Transition from numpy.distutils to scikit-build #3" note in the file header is removed.test_basic.py: addtest_docstring, checking each ufunc docstring contains noDOC_and has itsParameterssection.Every
DOC_*macro referenced by the generated code is defined by the generated header, and bothufunc_docstrings_numpy1.pyandufunc_docstrings_numpy2.pyuse thenumpy._core.umathkeys the generator expects. The header splits docstrings into adjacent literals at newlines, as NumPy does, so MSVC's string literal length limit is not hit.Testing
Linux,
icx, Python 3.13, NumPy 2.5.4: full test suite passes (450 passed, 1 skipped). The new test fails for all 58 ufuncs on a build frommain. Windows, clang and NumPy 1.x builds are covered by CI.