BUG: Ensure that same-kind casting works for uints (mostly) #27802
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 is the most minimal fix I could think off... If we have uints still use the out-of-bounds value, but make it uint. This is because the code uses copyto with the default same-kind casting in places...
This doesn't remove all the other quirks, and surely, it is a behavior change in some awkward situations (since you got a uint, someone might mix the newly uint value with an integer and get float64 results, etc.)
But... it is by far the most minimal fix I could think of after a longer time.
A more thorough fix may be to just always store the exact dtype, but it would propagate differently e.g. when casting. A start for this is currently in gh-27596.
Closes gh-27269, gh-27580
I am not convinced we should backport this or not. It is the most minimal fix I could think of (besides adding unsafe casts everywhere and hoping for the best/that we found them all). But it clearly has the potential to change behavior in some contexts...