Skip to content

ENH: Add a __dict__ to ufunc objects and allow overriding __doc__#27735

Merged
ngoldbaum merged 7 commits into
numpy:mainfrom
mtsokol:ufunc-object-dict
Nov 13, 2024
Merged

ENH: Add a __dict__ to ufunc objects and allow overriding __doc__#27735
ngoldbaum merged 7 commits into
numpy:mainfrom
mtsokol:ufunc-object-dict

Conversation

@mtsokol
Copy link
Copy Markdown
Member

@mtsokol mtsokol commented Nov 11, 2024

Hi @ngoldbaum, @mhvk,

This PR fixes #26233 and replaces #27383 (with existing review comments applied).

… `__doc__`

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the nitpick on the tests, this looks great!

Comment thread numpy/_core/tests/test_umath.py
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, looks fine to me as well, but also some comments. I mostly still think that we should also note other things like module and qualname (which have very clear use-cases as well).

Comment thread numpy/_core/src/umath/ufunc_object.c
Comment thread doc/release/upcoming_changes/27735.new_feature.rst Outdated
Comment thread numpy/_core/src/umath/ufunc_object.c Outdated
Comment thread numpy/_core/src/umath/ufunc_object.c
@mtsokol mtsokol force-pushed the ufunc-object-dict branch 3 times, most recently from ccdeffb to 1aae07d Compare November 12, 2024 13:37
Comment thread numpy/_core/src/umath/ufunc_object.c Outdated
@ngoldbaum
Copy link
Copy Markdown
Member

As a followup we should probably set __module__ on all of NumPy's built-in ufuncs so they show up where they're supposed to be in the public API instead of _multiarray_umath

@ngoldbaum
Copy link
Copy Markdown
Member

Maybe we can sneak in a deprecation warning into _add_newdoc_ufunc in this PR? It’s in np._core but we told people to continue using it because of the issue fixed by this PR.

@mtsokol
Copy link
Copy Markdown
Member Author

mtsokol commented Nov 12, 2024

Maybe we can sneak in a deprecation warning into _add_newdoc_ufunc in this PR?

@ngoldbaum Done!

I think all is ready now.

``__qualname__``.

* ``_add_newdoc_ufunc`` is now deprecated. ``ufunc.__doc__ = newdoc`` should
be used instead. No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but it should be split into two files (different categories).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, done!

@mattip
Copy link
Copy Markdown
Member

mattip commented Nov 13, 2024

We discussed this at the triage meeting and would like to see it merged in.

@ngoldbaum
Copy link
Copy Markdown
Member

I gave the C code another once-over and I think this is correct. I'll merge now. We should definitely update the way we set docstrings internally to make use of this as a followup, fixing #10167 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: add __dict__ to the ufunc object

5 participants