diff --git a/extra_data/stacking.py b/extra_data/stacking.py index 151934e0..9322eefb 100644 --- a/extra_data/stacking.py +++ b/extra_data/stacking.py @@ -1,6 +1,13 @@ import numpy as np import re +# numpy.exceptions exists from 1.25 onwards, but for Python 3.8 we still support +# numpy 1.24. We can clean this up once we require Python >= 3.9. +try: + from numpy.exceptions import AxisError +except ImportError: + from numpy import AxisError + __all__ = [ 'stack_data', 'stack_detector_data', @@ -238,7 +245,7 @@ def squeeze(self, axis=None): try: slices[ax] = 0 except IndexError: - raise np.AxisError( + raise AxisError( "axis {} is out of bounds for array of dimension {}" .format(ax, self.ndim) ) diff --git a/extra_data/tests/test_stacking.py b/extra_data/tests/test_stacking.py index 6f0cf213..fa63bc36 100644 --- a/extra_data/tests/test_stacking.py +++ b/extra_data/tests/test_stacking.py @@ -1,6 +1,13 @@ import numpy as np import pytest +# numpy.exceptions exists from 1.25 onwards, but for Python 3.8 we still support +# numpy 1.24. We can clean this up once we require Python >= 3.9. +try: + from numpy.exceptions import AxisError +except ImportError: + from numpy import AxisError + from extra_data import RunDirectory, stack_data, stack_detector_data from extra_data.stacking import StackView @@ -174,5 +181,5 @@ def test_stackview_squeeze(): assert sv.squeeze(axis=0).shape == (1, 4) assert sv.squeeze(axis=-2).shape == (1, 4) - with pytest.raises(np.AxisError): + with pytest.raises(AxisError): sv.squeeze(axis=4)