Skip to content

Commit 8ecdd84

Browse files
committed
Update failing pi test to add imports
1 parent f20967d commit 8ecdd84

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

enterprise_gateway/itests/test_python_kernel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ def test_run_pi_example(self):
124124
pi_code.append("from operator import add\n")
125125
pi_code.append("partitions = 20\n")
126126
pi_code.append("n = 100000 * partitions\n")
127+
# Define the function with explicit imports inside to avoid serialization issues
127128
pi_code.append("def f(_):\n")
129+
pi_code.append(" from random import random\n") # Include import inside function
128130
pi_code.append(" x = random() * 2 - 1\n")
129131
pi_code.append(" y = random() * 2 - 1\n")
130132
pi_code.append(" return 1 if x ** 2 + y ** 2 <= 1 else 0\n")
133+
# Use a lambda function directly in map to avoid complex serialization
131134
pi_code.append("count = sc.parallelize(range(1, n + 1), partitions).map(f).reduce(add)\n")
132135
pi_code.append('print("Pi is roughly %f" % (4.0 * count / n))\n')
133136
result, has_error = self.kernel.execute(pi_code)

0 commit comments

Comments
 (0)