MCPcopy Create free account
hub / github.com/numpy/numpy / test_simple

Method test_simple

numpy/core/tests/test_item_selection.py:93–107  ·  view source on GitHub ↗
(self, dtype)

Source from the content-addressed store, hash-verified

91class TestPutMask:
92 @pytest.mark.parametrize("dtype", list(np.typecodes["All"]) + ["i,O"])
93 def test_simple(self, dtype):
94 if dtype.lower() == "m":
95 dtype += "8[ns]"
96
97 # putmask is weird and doesn't care about value length (even shorter)
98 vals = np.arange(1001).astype(dtype=dtype)
99
100 mask = np.random.randint(2, size=1000).astype(bool)
101 # Use vals.dtype in case of flexible dtype (i.e. string)
102 arr = np.zeros(1000, dtype=vals.dtype)
103 zeros = arr.copy()
104
105 np.putmask(arr, mask, vals)
106 assert_array_equal(arr[mask], vals[:len(mask)][mask])
107 assert_array_equal(arr[~mask], zeros[~mask])
108
109 @pytest.mark.parametrize("dtype", list(np.typecodes["All"])[1:] + ["i,O"])
110 @pytest.mark.parametrize("mode", ["raise", "wrap", "clip"])

Callers

nothing calls this directly

Calls 4

assert_array_equalFunction · 0.90
lowerMethod · 0.80
astypeMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected