|
14 | 14 | from astropy import units as u |
15 | 15 | from astropy.coordinates import Longitude |
16 | 16 | from astropy.units import Quantity |
17 | | -from astropy.utils.compat import NUMPY_LT_2_2, NUMPY_LT_2_3 |
| 17 | +from astropy.utils.compat import NUMPY_LT_2_1, NUMPY_LT_2_2, NUMPY_LT_2_3 |
18 | 18 | from astropy.utils.compat.optional_deps import HAS_PLT |
19 | 19 | from astropy.utils.masked import Masked, MaskedNDArray |
20 | 20 |
|
@@ -304,8 +304,11 @@ def test_viewing(self): |
304 | 304 |
|
305 | 305 | def test_viewing_independent_shape(self): |
306 | 306 | mms = Masked(self.a, mask=self.m) |
307 | | - mms2 = mms.view() |
308 | | - mms2.shape = mms2.shape[::-1] |
| 307 | + if NUMPY_LT_2_1: |
| 308 | + mms2 = mms.view() |
| 309 | + mms2.shape = mms2.shape[::-1] |
| 310 | + else: |
| 311 | + mms2 = np.reshape(mms, mms.shape[::-1], copy=False) |
309 | 312 | assert mms2.shape == mms.shape[::-1] |
310 | 313 | assert mms2.mask.shape == mms.shape[::-1] |
311 | 314 | # This should not affect the original array! |
@@ -563,14 +566,21 @@ def test_reshape(self): |
563 | 566 | assert_array_equal(ma_reshape.mask, expected_mask) |
564 | 567 |
|
565 | 568 | def test_shape_setting(self): |
566 | | - ma_reshape = self.ma.copy() |
567 | | - ma_reshape.shape = (6,) |
| 569 | + if NUMPY_LT_2_1: |
| 570 | + ma_reshape = self.ma.copy() |
| 571 | + ma_reshape.shape = (6,) |
| 572 | + else: |
| 573 | + ma_reshape = np.reshape(self.ma, (6,), copy=True) |
| 574 | + |
568 | 575 | expected_data = self.a.reshape((6,)) |
569 | 576 | expected_mask = self.mask_a.reshape((6,)) |
570 | 577 | assert ma_reshape.shape == expected_data.shape |
571 | 578 | assert_array_equal(ma_reshape.unmasked, expected_data) |
572 | 579 | assert_array_equal(ma_reshape.mask, expected_mask) |
573 | 580 |
|
| 581 | + @pytest.mark.filterwarnings( |
| 582 | + "default:Setting the shape on a NumPy array has been deprecated in NumPy 2.5:DeprecationWarning" |
| 583 | + ) |
574 | 584 | def test_shape_setting_failure(self): |
575 | 585 | ma = self.ma.copy() |
576 | 586 | with pytest.raises(ValueError, match="cannot reshape"): |
|
0 commit comments