numpy.astype casting='unsafe' warning behavior in NumPy 1.26+
0 reputation · 25 Jan 2021, 07:46 UTC
Unclear warning policy for NumPy astype with casting='unsafe'
NumPy 1.26 added an explicit casting argument to ndarray.astype, allowing the unsafe mode that permits precision loss without raising an error. The documentation does not specify whether a warning should be emitted when data loss occurs (e.g., complex → float or float → int) under this mode.
This omission leaves the behavior as an unresolved decision that could lead to silent corruption in workflows requiring strict type fidelity.
Should NumPy emit a warning for such losses, and if so, under what conditions? How can users enable or suppress these warnings? What version‑specific policy would balance backward compatibility with data‑integrity guarantees?