Skip to content

Commit c203601

Browse files
author
Luke Shaw
committed
Adding comments
1 parent 09b80e3 commit c203601

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/blosc2/lazyexpr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ def compute_smaller_slice(larger_shape, smaller_shape, larger_slice):
541541

542542
# Define the patterns for validation
543543
validation_patterns = [
544-
# r"[\;\[\:]", # Flow control characters
545544
r"[\;]", # Flow control characters
546545
r"(^|[^\w])__[\w]+__($|[^\w])", # Dunder methods
547546
r"\.\b(?!real|imag|(\d*[eE]?[+-]?\d+)|(\d*[eE]?[+-]?\d+j)|\d*j\b|(sum|prod|min|max|std|mean|var|any|all|where)"
@@ -747,7 +746,8 @@ def visit_Call(self, node):
747746

748747
def convert_to_slice(expression):
749748
"""
750-
Assumes all operands are of the form o...
749+
Takes expression and converts all instances of [] to .slice(....)
750+
751751
Parameters
752752
----------
753753
expression: str
@@ -770,6 +770,8 @@ def convert_to_slice(expression):
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)
773+
# use slice so that lazyexpr uses blosc arrays internally
774+
# (and doesn't decompress according to getitem syntax)
773775
new_expr += ".slice(" + slicer + ")"
774776
skip_to_char = i + k + 1
775777
else:

tests/ndarray/test_reductions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ def test_slicebrackets_lazy():
445445
newarr = arr.compute()
446446
np.testing.assert_allclose(newarr[:], a[10:15] + 1)
447447

448+
# Try with getitem
449+
a = blosc2.linspace(0, 20, num=np.prod(shape), shape=shape)
450+
arr = blosc2.lazyexpr("anarr[10:15] + 1", {"anarr": a})
451+
newarr = arr[:3]
452+
res = a[10:15] + 1
453+
np.testing.assert_allclose(newarr, res[:3])
454+
448455
arr = blosc2.lazyexpr("anarr[10:15, 2:9] + 1", {"anarr": a})
449456
newarr = arr.compute()
450457
np.testing.assert_allclose(newarr[:], a[10:15, 2:9] + 1)

0 commit comments

Comments
 (0)