Skip to content

Commit 0eefad5

Browse files
committed
Put invariant out of the loop
1 parent 35a23c1 commit 0eefad5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/blosc2/ndarray.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,17 +3559,17 @@ def concatenate(arrays: list[NDArray], /, axis=0, **kwargs: Any) -> NDArray: #
35593559
if not isinstance(arr1, blosc2.NDArray):
35603560
raise TypeError("All inputs must be instances of blosc2.NDArray")
35613561
# Do a first pass for checking array compatibility
3562+
if axis < 0:
3563+
axis += arr1.ndim
3564+
if axis >= arr1.ndim:
3565+
raise ValueError(f"Axis {axis} is out of bounds for array of dimension {arr1.ndim}.")
35623566
for arr2 in arrays[1:]:
35633567
if not isinstance(arr2, blosc2.NDArray):
35643568
raise TypeError("All inputs must be instances of blosc2.NDArray")
35653569
if arr1.ndim != arr2.ndim:
35663570
raise ValueError("Both arrays must have the same number of dimensions for concatenation.")
35673571
if arr1.dtype != arr2.dtype:
35683572
raise ValueError("Both arrays must have the same dtype for concatenation.")
3569-
if axis < 0:
3570-
axis += arr1.ndim
3571-
if axis >= arr1.ndim:
3572-
raise ValueError(f"Axis {axis} is out of bounds for array of dimension {arr1.ndim}.")
35733573
# Check that the shapes match, except for the concatenation axis
35743574
if arr1.shape[:axis] != arr2.shape[:axis] or arr1.shape[axis + 1 :] != arr2.shape[axis + 1 :]:
35753575
raise ValueError(

0 commit comments

Comments
 (0)