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

Function test_nanfunctions_matrices

numpy/matrixlib/tests/test_interaction.py:162–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

160
161
162def test_nanfunctions_matrices():
163 # Check that it works and that type and
164 # shape are preserved
165 # 2018-04-29: moved here from core.tests.test_nanfunctions
166 mat = np.matrix(np.eye(3))
167 for f in [np.nanmin, np.nanmax]:
168 res = f(mat, axis=0)
169 assert_(isinstance(res, np.matrix))
170 assert_(res.shape == (1, 3))
171 res = f(mat, axis=1)
172 assert_(isinstance(res, np.matrix))
173 assert_(res.shape == (3, 1))
174 res = f(mat)
175 assert_(np.isscalar(res))
176 # check that rows of nan are dealt with for subclasses (#4628)
177 mat[1] = np.nan
178 for f in [np.nanmin, np.nanmax]:
179 with warnings.catch_warnings(record=True) as w:
180 warnings.simplefilter('always')
181 res = f(mat, axis=0)
182 assert_(isinstance(res, np.matrix))
183 assert_(not np.any(np.isnan(res)))
184 assert_(len(w) == 0)
185
186 with warnings.catch_warnings(record=True) as w:
187 warnings.simplefilter('always')
188 res = f(mat, axis=1)
189 assert_(isinstance(res, np.matrix))
190 assert_(np.isnan(res[1, 0]) and not np.isnan(res[0, 0])
191 and not np.isnan(res[2, 0]))
192 assert_(len(w) == 1, 'no warning raised')
193 assert_(issubclass(w[0].category, RuntimeWarning))
194
195 with warnings.catch_warnings(record=True) as w:
196 warnings.simplefilter('always')
197 res = f(mat)
198 assert_(np.isscalar(res))
199 assert_(res != np.nan)
200 assert_(len(w) == 0)
201
202
203def test_nanfunctions_matrices_general():

Callers

nothing calls this directly

Calls 3

assert_Function · 0.90
fFunction · 0.85
anyMethod · 0.45

Tested by

no test coverage detected