Test that _replace_nan returns the original array if there are no NaNs, not a copy.
()
| 1242 | |
| 1243 | |
| 1244 | def test__replace_nan(): |
| 1245 | """ Test that _replace_nan returns the original array if there are no |
| 1246 | NaNs, not a copy. |
| 1247 | """ |
| 1248 | for dtype in [np.bool_, np.int32, np.int64]: |
| 1249 | arr = np.array([0, 1], dtype=dtype) |
| 1250 | result, mask = _replace_nan(arr, 0) |
| 1251 | assert mask is None |
| 1252 | # do not make a copy if there are no nans |
| 1253 | assert result is arr |
| 1254 | |
| 1255 | for dtype in [np.float32, np.float64]: |
| 1256 | arr = np.array([0, 1], dtype=dtype) |
| 1257 | result, mask = _replace_nan(arr, 2) |
| 1258 | assert (mask == False).all() |
| 1259 | # mask is not None, so we make a copy |
| 1260 | assert result is not arr |
| 1261 | assert_equal(result, arr) |
| 1262 | |
| 1263 | arr_nan = np.array([0, 1, np.nan], dtype=dtype) |
| 1264 | result_nan, mask_nan = _replace_nan(arr_nan, 2) |
| 1265 | assert_equal(mask_nan, np.array([False, False, True])) |
| 1266 | assert result_nan is not arr_nan |
| 1267 | assert_equal(result_nan, np.array([0, 1, 2])) |
| 1268 | assert np.isnan(arr_nan[-1]) |
nothing calls this directly
no test coverage detected