Skip to content

Commit 0ff33c1

Browse files
committed
add test
1 parent b4571ee commit 0ff33c1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python/pyarrow/tests/test_gandiva.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import pyarrow as pa
1919
import pyarrow.gandiva as gandiva
2020

21+
import pandas as pd
22+
2123

2224
def test_tree_exp_builder():
2325
builder = gandiva.TreeExprBuilder()
@@ -48,3 +50,26 @@ def test_tree_exp_builder():
4850

4951
r, = projector.evaluate(input_batch)
5052
assert r.equals(e)
53+
54+
def test_table():
55+
df = pd.DataFrame({"a": [1.0, 2.0], "b": [3.0, 4.0]})
56+
table = pa.Table.from_pandas(df)
57+
58+
builder = gandiva.TreeExprBuilder()
59+
node_a = builder.make_field(table.schema.field_by_name("a"))
60+
node_b = builder.make_field(table.schema.field_by_name("b"))
61+
62+
sum = builder.make_function(b"add", [node_a, node_b], pa.float64())
63+
64+
field_result = pa.field("c", pa.float64())
65+
expr = builder.make_expression(sum, field_result)
66+
67+
projector = gandiva.make_projector(
68+
table.schema, [expr], pa.default_memory_pool())
69+
70+
# TODO: Add .evaluate function which can take Tables instead of
71+
# RecordBatches
72+
r, = projector.evaluate(table.to_batches()[0])
73+
74+
e = pa.Array.from_pandas(df["a"] + df["b"])
75+
assert r.equals(e)

0 commit comments

Comments
 (0)