| 160 | |
| 161 | |
| 162 | def 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 | |
| 203 | def test_nanfunctions_matrices_general(): |