Skip to content

Commit

Permalink
Fix location of AxisError
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Jun 18, 2024
1 parent 50f1361 commit 2a1bfc4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion extra_data/stacking.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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)
)
Expand Down
9 changes: 8 additions & 1 deletion extra_data/tests/test_stacking.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 2a1bfc4

Please sign in to comment.