In PR 29129 <https://github.com/numpy/numpy/pull/29129> I propose to add a new casting option to ndarray.astype(dtype, casting='XXX') called same_value. It changes the inner casting loop to check that the value round-trips, and raises a value error on overflow or float-to-int truncation. While the PR adds infrastructure for further same_value casting in user-defined dtypes and elsewhere in NumPy, the current work is only exposed in ndarray.astype (and not in np.astype, since there is no casting option in that function).
This was motivated by user desire to have some kind of value-based casting. See also the discussion of saturation-based ufuncs <https://mail.python.org/archives/list/[email protected]/thread/B66THXMXAAC33UORRFOZGLTFKCU7VUBM/#B66THXMXAAC33UORRFOZGLTFKCU7VUBM> What do you think? Matti
_______________________________________________ NumPy-Discussion mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/numpy-discussion.python.org Member address: [email protected]
