Skip to content

Commit cb2b4d3

Browse files
Merge pull request #402 from Blosc/fixIndexing
Fix indexing for lazy expressions, and allow use of None in getitem
2 parents e1af9b4 + f0ef6be commit cb2b4d3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/blosc2/lazyexpr.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,16 +2440,17 @@ def _compute_expr(self, item, kwargs): # noqa: C901
24402440
if len(self._where_args) == 1:
24412441
# We have a single argument
24422442
where_x = self._where_args["_where_x"]
2443-
return where_x[:][lazy_expr]
2443+
return (where_x[:][lazy_expr])[item]
24442444
if len(self._where_args) == 2:
24452445
# We have two arguments
24462446
where_x = self._where_args["_where_x"]
24472447
where_y = self._where_args["_where_y"]
2448-
return np.where(lazy_expr, where_x, where_y)
2448+
return np.where(lazy_expr, where_x, where_y)[item]
24492449
if hasattr(self, "_output"):
24502450
# This is not exactly optimized, but it works for now
2451-
self._output[:] = lazy_expr
2452-
return lazy_expr
2451+
self._output[:] = lazy_expr[item]
2452+
return self._output
2453+
return lazy_expr[item]
24532454

24542455
return chunked_eval(lazy_expr.expression, lazy_expr.operands, item, **kwargs)
24552456

tests/ndarray/test_reductions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,11 @@ def test_save_constructor_reduce2(shape, disk, compute):
418418
blosc2.remove_urlpath(urlpath_a)
419419
blosc2.remove_urlpath(urlpath_b)
420420
blosc2.remove_urlpath("out.b2nd")
421+
422+
423+
def test_reduction_index():
424+
shape = (20, 20)
425+
a = blosc2.linspace(0, 20, num=np.prod(shape), shape=shape)
426+
expr = blosc2.sum(a, axis=0)
427+
assert expr[:10].shape == (10,)
428+
assert expr[0].shape == ()

0 commit comments

Comments
 (0)