Repository navigation
ENH: Create helper for conversion to arrays - #24214
Merged
Merged
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.
Had to give this a start to be able to experiment. It does solve at least some problems (e.g.
np.select()use-case and it looks like it would fix and/or simplify linalg code).The main thing is that we often convert multiple arrays, and then want something like:
a, b, c = np.asarray(a), np.asarray(b), np.asarray(c)and thendtype = np.result_type(a, b, c)often with an additional0.0. That is a pretty common pattern, NEP 50 makes it tricky if you wish to support weak scalars, because you need to callresult_typewith the scalar information intact (before theasarrayor manually undo). (For example, this happens innp.select())__array_wrap__for subclass support, although it seems consistently used for single input functions (outside ufuncs).First, I wanted to just make a single function. But with multiple things above that may be interesting to return, and e.g.
result_type()might error and I am not sure we always need it.So, is it insane to create a rich object (rather than a complicated return value and many kwargs):
(I can see
a, b, info = helper(a, b)as a nice pattern; OTOH it makes including casting kwarg heavy since you somewhat need to include it in the first step.)Further things might include:
arrays.to_common_dtype(ensure_inexact=True))