Skip to content

Commit 487edc2

Browse files
Fixed start_col variable (#35)
1 parent cc05efc commit 487edc2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

exasol_udf_mock_python/mock_context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ def get_dataframe(self, num_rows='all', start_col=0):
6161
raise RuntimeError("get_dataframe() parameter 'start_col' must be an integer >= 0")
6262
if self._data is None:
6363
return None
64-
columns_ = [column.name for column in self._metadata.input_columns]
64+
columns_ = [column.name for column in self._metadata.input_columns[start_col:]]
6565

6666
i = 0
6767
df = None
6868
while num_rows == 'all' or i < num_rows:
69-
df_current = pd.DataFrame.from_records([self._data], columns=columns_)
69+
df_current = pd.DataFrame.from_records(
70+
[self._data[start_col:]], columns=columns_)
7071
if df is None:
7172
df = df_current
7273
else:

tests/test_executor_context_set_emits.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def run(ctx):
311311
with pytest.raises(RuntimeError) as excinfo:
312312
result = executor.run([Group([(1,), (2,), (3,), (4,), (5,), (6,)])], exa)
313313

314+
314315
def test_get_dataframe_start_col_0():
315316
def udf_wrapper():
316317
def run(ctx):
@@ -329,23 +330,27 @@ def run(ctx):
329330
result = executor.run([Group([(1,), (2,), (3,), (4,), (5,), (6,)])], exa)
330331
assert result == [Group([(1,), ])]
331332

333+
332334
def test_get_dataframe_start_col_positive():
333335
def udf_wrapper():
334336
def run(ctx):
335337
df = ctx.get_dataframe(num_rows=1, start_col=1)
336338
ctx.emit(df)
337339

338-
executor = UDFMockExecutor()
339340
meta = MockMetaData(
340341
script_code_wrapper_function=udf_wrapper,
341342
input_type="SET",
342-
input_columns=[Column("t", int, "INTEGER")],
343+
input_columns=[
344+
Column("t1", int, "INTEGER"),
345+
Column("t2", int, "INTEGER")],
343346
output_type="EMITS",
344347
output_columns=[Column("t", int, "INTEGER")]
345348
)
349+
executor = UDFMockExecutor()
346350
exa = MockExaEnvironment(meta)
347-
result = executor.run([Group([(1,), (2,), (3,), (4,), (5,), (6,)])], exa)
348-
assert result == [Group([(1,), ])]
351+
result = executor.run([Group([(1, -1), (2, -2), (3, -3), (4, -4)])], exa)
352+
assert result == [Group([(-1,), ])]
353+
349354

350355
def test_emit_tuple_exception():
351356
def udf_wrapper():

0 commit comments

Comments
 (0)