Skip to content

Commit 0b4f600

Browse files
author
Luke Shaw
committed
Fixed bug for integer indexes
1 parent c203601 commit 0b4f600

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/blosc2/lazyexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def convert_to_slice(expression):
766766
k = expression[i:].find("]") # start checking from after [
767767
slice_convert = expression[i : i + k + 1] # include [ and ]
768768
slicer = eval(f"np.s_{slice_convert}")
769-
slicer = (slicer,) if isinstance(slicer, slice) else slicer # standardise to tuple
769+
slicer = (slicer,) if not isinstance(slicer, tuple) else slicer # standardise to tuple
770770
if any(isinstance(el, str) for el in slicer): # handle fields
771771
raise ValueError("Cannot handle fields for slicing lazy expressions.")
772772
slicer = str(slicer)

tests/ndarray/test_reductions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,19 @@ def test_slicebrackets_lazy():
452452
res = a[10:15] + 1
453453
np.testing.assert_allclose(newarr, res[:3])
454454

455+
# Test other cases
455456
arr = blosc2.lazyexpr("anarr[10:15, 2:9] + 1", {"anarr": a})
456457
newarr = arr.compute()
457458
np.testing.assert_allclose(newarr[:], a[10:15, 2:9] + 1)
458459

459460
arr = blosc2.lazyexpr("anarr[10:15][2:9] + 1", {"anarr": a})
460461
newarr = arr.compute()
461462
np.testing.assert_allclose(newarr[:], a[10:15][2:9] + 1)
463+
464+
arr = blosc2.lazyexpr("anarr[10] + 1", {"anarr": a})
465+
newarr = arr.compute()
466+
np.testing.assert_allclose(newarr[:], a[10] + 1)
467+
468+
arr = blosc2.lazyexpr("anarr[10, 1] + 1", {"anarr": a})
469+
newarr = arr[:]
470+
np.testing.assert_allclose(newarr, a[10, 1] + 1)

0 commit comments

Comments
 (0)