Repository navigation
Conversation
This branch has not been deployed
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.
PR summary
dtype.namegoes through_name_getin_dtype.py. Most of its time went to_name_includes_bit_suffix, which callednp.issubdtype(dtype, np.flexible). It now callsissubclass(dtype.type, np.flexible), which gives the same answer becausedtype.typeis already a scalar type at that point. The C getter also re-importednumpy._core._dtypeand looked up_name_getby name on every access. It now caches the function in the module's runtime imports, the same way_commastringand_usefieldsare cached.Timings with the reproducer from the issue (macOS arm64, Python 3.14):
float32int64bool<U5datetime64[ns]StringDType()The returned names don't change. Almost all of the remaining time is spent in the Python function itself, so getting down to tens of nanoseconds would mean moving
_name_getto C.Closes #33051
AI Disclosure
I used Claude Code here. It profiled
dtype.nameand drafted the change, so the edits todescriptor.c,module_state_fields.hand_dtype.pyand the text of this description are AI generated. I built numpy from source and checked the timings and the test suite myself before opening the PR.