MCPcopy Index your code
hub / github.com/numpy/numpy / test__replace_nan

Function test__replace_nan

numpy/lib/tests/test_nanfunctions.py:1409–1433  ·  view source on GitHub ↗

Test that _replace_nan returns the original array if there are no NaNs, not a copy.

()

Source from the content-addressed store, hash-verified

1407
1408
1409def 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)")

Callers

nothing calls this directly

Calls 3

_replace_nanFunction · 0.90
assert_equalFunction · 0.90
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…