Create array with NaN values, handling cast warnings for int dtypes.
(values, dtype)
| 31 | |
| 32 | |
| 33 | def create_nan_array(values, dtype): |
| 34 | """Create array with NaN values, handling cast warnings for int dtypes.""" |
| 35 | import warnings |
| 36 | |
| 37 | # When casting float arrays with NaN to integer, NumPy raises a warning |
| 38 | # This is expected behavior when dtype is int |
| 39 | with warnings.catch_warnings(): |
| 40 | if np.issubdtype(dtype, np.integer): |
| 41 | warnings.filterwarnings("ignore", "invalid value encountered in cast") |
| 42 | return np.array(values).astype(dtype) |
| 43 | |
| 44 | |
| 45 | # make sure scalars are converted to 0d arrays so quantities can |
no test coverage detected
searching dependent graphs…