API: Allow comparisons with and between any python integers #24915
Merged
ngoldbaum merged 8 commits intonumpy:mainfrom Oct 19, 2023
Merged
API: Allow comparisons with and between any python integers #24915ngoldbaum merged 8 commits intonumpy:mainfrom
ngoldbaum merged 8 commits intonumpy:mainfrom
Conversation
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.
This implements comparisons between NumPy integer arrays and arbitrary valued
Python integers when weak promotion is enabled.
To achieve this:
ArrayMethods).This is fine, you just need to take more care.
It does muddy the waters between promotion and not a bit if the
result DType would also be abstract.
(For the specific case it doesn't, but in general it does.)
resolve_descriptors_rawfunction, which does the same job asresolve_descriptorsbut I pass it this scalar argument(can be expanded, but starting small).
be used (
ufunc.atand the explicit resolution function right now),we can deal with those by keeping the previous rules (things will just raise
trying to convert).
arrays.dtypeinstances while I normally ensure thatwe pass in dtypes already cast to the correct DType class.
(The reason is that we don't define how to cast the abstract DTypes as of now,
and even if we did, it would not be what we need unless the dtype instance actually had
the value information.)
resolve_descriptors_raw(a single function dealing with everything)get_loop()needs to know the value,but only
resolve_descriptors_raw()does right now, so this is encoded on whether we usethe
np.dtype("object")singleton or a fresh instance!(Yes, probably ugly, but avoids channeling things to more places.)
Additionally, there is a promoter to say that Python integer comparisons can just use
objectdtype (in theory weird if the input then wasn't a Python int,but that is breaking promises).
This is the split out from gh-23912, to solve the biggest pain point/problem. Comparisons with Python integers that are out-of-bounds.
May need a bit of cleanup, but the main discussion should be if the appraoch is really what we want (but we really need something).