Skip to content

Commit 726ca2c

Browse files
committed
Save LazyUDF such that source remains available
1 parent 0be6643 commit 726ca2c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/blosc2/lazyexpr.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import concurrent.futures
1515
import copy
1616
import inspect
17+
import linecache
1718
import math
1819
import os
1920
import pathlib
@@ -3648,8 +3649,13 @@ def _open_lazyarray(array):
36483649
new_expr = LazyExpr._new_expr(expr, operands_dict, guess=True, out=None, where=None)
36493650
elif value == LazyArrayEnum.UDF.value:
36503651
local_ns = {}
3651-
exec(expr, {"np": np, "blosc2": blosc2}, local_ns)
36523652
name = lazyarray["name"]
3653+
filename = f"<{name}>" # any unique name
3654+
3655+
# Register the source so inspect can find it
3656+
linecache.cache[filename] = (len(expr), None, expr.splitlines(True), filename)
3657+
3658+
exec(compile(expr, filename, "exec"), {"np": np, "blosc2": blosc2}, local_ns)
36533659
func = local_ns[name]
36543660
# TODO: make more robust for general kwargs (not just cparams)
36553661
new_expr = blosc2.lazyudf(

0 commit comments

Comments
 (0)