Align casting methods with Python behaviour#497
Conversation
x.__complex__(), unrestrict cross-kind casting in respective array methods|
Per what we decided upon in our last array meeting (see #486 (comment)), I've updated this PR with my take on how to we align the spec's casting methods with Python's behaviour. I have some thorough testing for how Python's casting works in https://gist.github.com/honno/98371048b4d5b9fc4a003377a714e827, which I'll have to tidy up (will be useful anyway for the test suite). As @seberg noted, NumPy seems to 100% follow Python casting behaviour for its arrays (if we're not including a small divergence in behaviour for NumPy scalars). Only notable thing maybe is NumPy not aligning with Python's Not 100% on language used, happy to hear what folk think. Will sleep on it anyway. |
honno
left a comment
There was a problem hiding this comment.
Just realised I should probably special case non-finite values for __bool__.
|
Think this is ready @seberg @asmeurer? With the follow up of specifying |
Co-authored-by: Athan <kgryte@gmail.com>
|
I believe all discussion points have been resolved. I'll go ahead and merge. Any further changes can be addressed in follow-up PRs. Thanks, all! |
Resolves #486 (adding
x.__complex__()).Per interest in having the builtin casting methods (
__bool__/__int__/__float__/__complex__/__index__) support arrays of a different dtype kind, this PR also changes the language to clarify that adopters can support such casting. EDIT: now aligning casting methods with Python behaviour generally(I opted against requiring cross-kind casting in this PR—see #486 (comment))See #486 (comment)