Skip to content

Commit d698a98

Browse files
committed
Add tests for showing DataFrames with no rows and improve output messages
1 parent 42c5cb8 commit d698a98

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

python/tests/test_dataframe.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,31 +2665,17 @@ def trigger_interrupt():
26652665
# Make sure the interrupt thread has finished
26662666
interrupt_thread.join(timeout=1.0)
26672667

2668+
def test_show_select_where_no_rows(capsys) -> None:
2669+
ctx = SessionContext()
2670+
df = ctx.sql("SELECT 1 WHERE 1=0")
2671+
df.show()
2672+
out = capsys.readouterr().out
2673+
assert "DataFrame has no rows" in out
26682674

2669-
def test_show_from_empty_rows(capsys):
2670-
"""Create a DataFrame with a valid schema but zero rows and call show().
2671-
2672-
This verifies that showing an empty-but-schema'd DataFrame does not panic
2673-
and prints a helpful message instead.
2674-
"""
2675-
# duplicate of test_show_empty; covered elsewhere
2676-
pass
2677-
2678-
2679-
def test_select_where_no_rows(capsys):
2680-
"""Create a DataFrame a:[1,2,3], filter with a>4 to produce zero rows and call show().
2681-
2682-
This verifies that a query returning zero rows does not trigger a panic and
2683-
instead prints a helpful message.
2684-
"""
2685-
# duplicate of test_show_empty; covered elsewhere
2686-
pass
2687-
2688-
2689-
def test_sql_select_where_no_rows(capsys):
2690-
"""Register a table 't' with a:[1,2,3], run SQL that returns no rows, and call show().
26912675

2692-
Ensures SQL path that returns zero rows doesn't panic when showing results.
2693-
"""
2694-
# duplicate of test_show_empty; covered elsewhere
2695-
pass
2676+
def test_show_from_empty_batch(capsys) -> None:
2677+
ctx = SessionContext()
2678+
batch = pa.record_batch([pa.array([], type=pa.int32())], names=["a"])
2679+
ctx.create_dataframe([[batch]]).show()
2680+
out = capsys.readouterr().out
2681+
assert "| a |" in out

0 commit comments

Comments
 (0)