Test that _replace_nan returns the original array if there are no NaNs, not a copy.
()
| 1407 | |
| 1408 | |
| 1409 | def test__replace_nan(): |
| 1410 | """ Test that _replace_nan returns the original array if there are no |
| 1411 | NaNs, not a copy. |
| 1412 | """ |
| 1413 | for dtype in [np.bool, np.int32, np.int64]: |
| 1414 | arr = np.array([0, 1], dtype=dtype) |
| 1415 | result, mask = _replace_nan(arr, 0) |
| 1416 | assert mask is None |
| 1417 | # do not make a copy if there are no nans |
| 1418 | assert result is arr |
| 1419 | |
| 1420 | for dtype in [np.float32, np.float64]: |
| 1421 | arr = np.array([0, 1], dtype=dtype) |
| 1422 | result, mask = _replace_nan(arr, 2) |
| 1423 | assert (mask == False).all() |
| 1424 | # mask is not None, so we make a copy |
| 1425 | assert result is not arr |
| 1426 | assert_equal(result, arr) |
| 1427 | |
| 1428 | arr_nan = np.array([0, 1, np.nan], dtype=dtype) |
| 1429 | result_nan, mask_nan = _replace_nan(arr_nan, 2) |
| 1430 | assert_equal(mask_nan, np.array([False, False, True])) |
| 1431 | assert result_nan is not arr_nan |
| 1432 | assert_equal(result_nan, np.array([0, 1, 2])) |
| 1433 | assert np.isnan(arr_nan[-1]) |
| 1434 | |
| 1435 | |
| 1436 | @pytest.mark.thread_unsafe(reason="memmap is thread-unsafe (gh-29126)") |
nothing calls this directly
no test coverage detected
searching dependent graphs…