Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly check for main module when blding scope #2770

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions py/server/deephaven/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def _query_scope_ctx():
break

# combine the immediate caller's globals and locals into a single dict and use it as the query scope
if len(outer_frames) > i + 2:
caller_frame, *_ = outer_frames[i + 1]
caller_frame = outer_frames[i + 1].frame
function = outer_frames[i + 1].function
if len(outer_frames) > i + 2 or function != "<module>":
scope_dict = caller_frame.f_globals.copy()
scope_dict.update(caller_frame.f_locals)
try:
Expand Down
23 changes: 22 additions & 1 deletion py/server/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from types import SimpleNamespace
from typing import List, Any

from deephaven import DHError, read_csv, empty_table, SortDirection, AsOfMatchRule, time_table
from deephaven import DHError, read_csv, empty_table, SortDirection, AsOfMatchRule, time_table, ugp
from deephaven.agg import sum_, weighted_avg, avg, pct, group, count_, first, last, max_, median, min_, std, abs_sum, \
var, formula, partition
from deephaven.pandas import to_pandas
Expand Down Expand Up @@ -629,6 +629,27 @@ def inner_func(p) -> str:
t = empty_table(1).update("X = i").update("TableString = inner_func(X + 10)")
self.assertIn("100", t.to_string())

def test_nested_scope_ticking(self):
import jpy
_JExecutionContext = jpy.get_type("io.deephaven.engine.context.ExecutionContext")
j_context = (_JExecutionContext.newBuilder()
.captureCompilerContext()
.captureQueryLibrary()
.captureQueryScope()
.build())

def inner_func(p) -> str:
open_ctx = j_context.open()
t = empty_table(1).update("X = p * 10")
open_ctx.close()
return t.to_string().split()[2]

with ugp.shared_lock():
t = time_table("00:00:01").update("X = i").update("TableString = inner_func(X + 10)")
self.wait_ticking_table_update(t, row_count=5, timeout=10)

self.assertIn("100", t.to_string())

def test_scope_comprehensions(self):
with self.subTest("List comprehension"):
t = empty_table(1)
Expand Down