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