From 7254133849ffee9e252c0ea8bc9dade0a4ea7f83 Mon Sep 17 00:00:00 2001 From: ump45nose <52391318+ump45nose@users.noreply.github.com> Date: Fri, 11 Sep 2026 23:10:40 +0800 Subject: [PATCH] fix: show results in the nine silent top-level examples Nine examples (`export.py`, `import.py`, `python-udaf.py`, `python-udf.py`, `query-pyarrow-data.py`, `sql-to-pandas.py`, `sql-using-python-udaf.py`, `sql-using-python-udf.py`, `substrait.py`) ended in bare asserts and printed nothing, so a reader running them sees no output and cannot tell a working script from a silent one (#1728). Each now shows its final result with `df.show()` or a terminal `print`, keeping the asserts. --- examples/export.py | 3 +++ examples/import.py | 3 +++ examples/python-udaf.py | 2 ++ examples/python-udf.py | 2 ++ examples/query-pyarrow-data.py | 2 ++ examples/sql-to-pandas.py | 2 ++ examples/sql-using-python-udaf.py | 1 + examples/sql-using-python-udf.py | 1 + examples/substrait.py | 2 ++ 9 files changed, 18 insertions(+) diff --git a/examples/export.py b/examples/export.py index c7a387bcb..404b758f2 100644 --- a/examples/export.py +++ b/examples/export.py @@ -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}") diff --git a/examples/import.py b/examples/import.py index 7b5ab5082..09fd4da4e 100644 --- a/examples/import.py +++ b/examples/import.py @@ -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() diff --git a/examples/python-udaf.py b/examples/python-udaf.py index 6655edb0a..2319f0cd0 100644 --- a/examples/python-udaf.py +++ b/examples/python-udaf.py @@ -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()}") diff --git a/examples/python-udf.py b/examples/python-udf.py index 1c08acd1a..b1b7f8797 100644 --- a/examples/python-udf.py +++ b/examples/python-udf.py @@ -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) diff --git a/examples/query-pyarrow-data.py b/examples/query-pyarrow-data.py index 9cfe8a62b..bb5a55336 100644 --- a/examples/query-pyarrow-data.py +++ b/examples/query-pyarrow-data.py @@ -35,6 +35,8 @@ col("a") - col("b"), ) +df.show() + # execute and collect the first (and only) batch result = df.collect()[0] diff --git a/examples/sql-to-pandas.py b/examples/sql-to-pandas.py index 34f7bde1b..c242add98 100644 --- a/examples/sql-to-pandas.py +++ b/examples/sql-to-pandas.py @@ -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") diff --git a/examples/sql-using-python-udaf.py b/examples/sql-using-python-udaf.py index f42bbdc23..b15d812ba 100644 --- a/examples/sql-using-python-udaf.py +++ b/examples/sql-using-python-udaf.py @@ -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 | diff --git a/examples/sql-using-python-udf.py b/examples/sql-using-python-udf.py index 2f0a0b67d..4edb653c7 100644 --- a/examples/sql-using-python-udf.py +++ b/examples/sql-using-python-udf.py @@ -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 | diff --git a/examples/substrait.py b/examples/substrait.py index fa6f77912..f122ae991 100644 --- a/examples/substrait.py +++ b/examples/substrait.py @@ -47,3 +47,5 @@ # Back to Substrait Plan just for demonstration purposes # type(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")