Skip to content
Open
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
3 changes: 3 additions & 0 deletions examples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@
# export to Python dictionary of columns
pydict = df.to_pydict()
assert pydict == {"a": [1, 2, 3], "b": [4, 5, 6]}

print(f"Exported as list of rows: {pylist}")
print(f"Exported as dict of columns: {pydict}")
3 changes: 3 additions & 0 deletions examples/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@
arrow_table = pa.Table.from_pydict({"a": [1, 2, 3], "b": [4, 5, 6]})
df = ctx.from_arrow(arrow_table)
assert type(df) is datafusion.DataFrame

# Display the last converted DataFrame
df.show()
2 changes: 2 additions & 0 deletions examples/python-udaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ def evaluate(self) -> pa.Scalar:
result = df.collect()[0]

assert result.column(0) == pa.array([6.0])

print(f"Sum of column 'a': {result.column(0)[0].as_py()}")
2 changes: 2 additions & 0 deletions examples/python-udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def is_null(array: pa.Array) -> pa.Array:

df = df.select(is_null_arr(f.col("a")))

df.show()

result = df.collect()[0]

assert result.column(0) == pa.array([False] * 3)
2 changes: 2 additions & 0 deletions examples/query-pyarrow-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
col("a") - col("b"),
)

df.show()

# execute and collect the first (and only) batch
result = df.collect()[0]

Expand Down
2 changes: 2 additions & 0 deletions examples/sql-to-pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@
kind="bar", title="Trip Count by Number of Passengers"
).get_figure()
fig.savefig("chart.png")

print("Saved chart to chart.png")
1 change: 1 addition & 0 deletions examples/sql-using-python-udaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def evaluate(self) -> pa.Scalar:
result_df = ctx.sql(
"select a, my_accumulator(b) as b_aggregated from t group by a order by a"
)
result_df.show()
# Dataframe:
# +---+--------------+
# | a | b_aggregated |
Expand Down
1 change: 1 addition & 0 deletions examples/sql-using-python-udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def is_null(array: pa.Array) -> pa.Array:

# Query the DataFrame using SQL
result_df = ctx.sql("select a, is_null(b) as b_is_null from t")
result_df.show()
# Dataframe:
# +---+-----------+
# | a | b_is_null |
Expand Down
2 changes: 2 additions & 0 deletions examples/substrait.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@
# Back to Substrait Plan just for demonstration purposes
# type(substrait_plan) -> <class 'datafusion.substrait.plan'>
substrait_plan = ss.Producer.to_substrait_plan(df_logical_plan, ctx)

print(f"Substrait plan round-trip complete: {len(substrait_bytes)} encoded bytes")