Skip to content

Commit 3b864ba

Browse files
committed
Improve dtype handling for lexprs with constructors
1 parent 9aa649e commit 3b864ba

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/blosc2/lazyexpr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,9 @@ def __init__(self, new_op): # noqa: C901
23412341
if value2 is None:
23422342
if isinstance(value1, LazyExpr):
23432343
self.expression = value1.expression if op is None else f"{op}({value1.expression})"
2344+
# handle constructors which can give empty operands
2345+
_out = _numpy_eval_expr(f"{op}(o0)", {"o0": value1}, prefer_blosc=False)
2346+
self._dtype = _out.dtype
23442347
self.operands = value1.operands
23452348
else:
23462349
if np.isscalar(value1):

tests/ndarray/test_lazyexpr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,10 @@ def test_str_constructors():
13651365
a = blosc2.lazyexpr(f"b + linspace(0, 100, {np.prod(shape)}, shape={shape}, chunks={chunks})")
13661366
assert a.shape == np.broadcast_shapes(shape, b.shape)
13671367

1368+
# failed before dtype handling improved
1369+
x = blosc2.lazyexpr("linspace(-1, 1, 10, shape=(1, 10))")
1370+
lexpr = blosc2.sin(blosc2.sqrt(x**2))
1371+
13681372

13691373
@pytest.mark.parametrize(
13701374
"obj",

0 commit comments

Comments
 (0)