Repository navigation
BUG: return scalar types from dtypes() and default_dtypes() - #480
Open
karandhaodiyal28-hash wants to merge 1 commit into
Open
karandhaodiyal28-hash wants to merge 1 commit into
karandhaodiyal28-hash wants to merge 1 commit into
Conversation
__array_namespace_info__().dtypes() and .default_dtypes() returned np.dtype objects instead of the scalar types. That causes two problems: - np.dtype(None) is float64 in NumPy, so dtypes()["float64"] == None is True and a caller cannot use None to mean "this dtype is unsupported". - np.dtype objects have no __name__, so the returned values cannot be introspected at all. This affects every dtype, not just float64. Both methods already document the scalar types in their docstrings, so this makes the code match its own documentation. The cupy and dask backends have the same pattern and already return a bare `bool` for the bool entry, so the scalar type is the intended convention here too. This only changes the numpy backend; cupy and dask are left alone since they cannot be exercised from the numpy-only test environment. Fixes data-apisgh-359
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Fixes gh-359.
__array_namespace_info__().dtypes()and.default_dtypes()returnnp.dtypeobjects instead of the scalar types:np.dtype(None)isfloat64in NumPy, sofloat64is the one dtype that spuriously compares equal toNone— a caller that usesNoneto mean "this dtype is unsupported" gets it backwards for the most important dtype. The missing__name__hits every dtype.Both docstrings already show the scalar types, so this brings the code in line with its own documentation. rgommers also suggested returning
np.float64rather thannp.dtype('float64')in gh-359, and the cupy/dask backends already return a bareboolfor the bool entry, so the scalar type looks like the intended convention here too.Scope note:
cupy/_info.pyanddask/array/_info.pyhave the same pattern, but I've left them untouched — I can only exercise the numpy backend locally.Changes:
src/array_api_compat/numpy/_info.py— drop thedtype(...)wrapper indtypes()anddefault_dtypes()tests/test_numpy.py— regression test (fails before this change, passes after)