Skip to content

Commit c3eefee

Browse files
committed
Revert "Fix not recalculating shape bug for lazyexprs"
This reverts commit 41c1ebe.
1 parent 41c1ebe commit c3eefee

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/blosc2/lazyexpr.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,17 +2573,19 @@ def shape(self):
25732573
return None
25742574

25752575
# Operands shape can change, so we always need to recompute this
2576-
if any(constructor in self.expression for constructor in constructors):
2577-
# might have an expression with pure constructors
2578-
opshapes = {k: v if not hasattr(v, "shape") else v.shape for k, v in self.operands.items()}
2579-
_shape = infer_shape(self.expression, opshapes) # infer shape, includes constructors
2580-
2581-
else:
2576+
try:
25822577
_shape, chunks, blocks, fast_path = validate_inputs(self.operands, getattr(self, "_out", None))
25832578
if fast_path:
25842579
# fast_path ensure that all the operands have the same partitions
25852580
self._chunks = chunks
25862581
self._blocks = blocks
2582+
except ValueError as e:
2583+
if any(constructor in self.expression for constructor in constructors):
2584+
# might have an expression with pure constructors
2585+
opshapes = {k: v if not hasattr(v, "shape") else v.shape for k, v in self.operands.items()}
2586+
_shape = infer_shape(self.expression, opshapes) # infer shape, includes constructors
2587+
else:
2588+
raise e
25872589

25882590
self._shape_ = _shape
25892591
self._expression_ = self.expression

tests/ndarray/test_lazyexpr.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -952,21 +952,6 @@ def test_broadcasting(broadcast_fixture):
952952
np.testing.assert_allclose(res, nres)
953953

954954

955-
def test_incompatible_shape():
956-
shape1 = (1000,)
957-
shape2 = (100,)
958-
a = blosc2.ones(shape1)
959-
b = blosc2.zeros(shape2)
960-
expr = a + b
961-
with pytest.raises(ValueError):
962-
s = expr.shape
963-
964-
# Test constructor too
965-
expr = a + blosc2.lazyexpr(f"linspace(0, 10, {np.prod(shape2)}, shape={shape2})")
966-
with pytest.raises(ValueError):
967-
s = expr.shape
968-
969-
970955
def test_broadcasting_str(broadcast_fixture):
971956
a1, a2, na1, na2 = broadcast_fixture
972957
expr1 = blosc2.lazyexpr("a1 + a2")

0 commit comments

Comments
 (0)