File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1464,6 +1464,14 @@ def test_empty_to_pandas(df):
14641464 assert set (pandas_df .columns ) == {"a" , "b" , "c" }
14651465
14661466
1467+ def test_show_empty_dataframe (df , capsys ):
1468+ """Ensure showing an empty DataFrame prints a helpful message."""
1469+ empty_df = df .limit (0 )
1470+ empty_df .show ()
1471+ captured = capsys .readouterr ()
1472+ assert "Empty DataFrame" in captured .out
1473+
1474+
14671475def test_to_polars (df ):
14681476 # Skip test if polars is not installed
14691477 pl = pytest .importorskip ("polars" )
Original file line number Diff line number Diff line change @@ -1046,10 +1046,14 @@ impl Iterator for ArrowStreamReader {
10461046fn print_dataframe ( py : Python , df : DataFrame ) -> PyDataFusionResult < ( ) > {
10471047 // Get string representation of record batches
10481048 let batches = wait_for_future ( py, df. collect ( ) ) ??;
1049- let batches_as_string = pretty:: pretty_format_batches ( & batches) ;
1050- let result = match batches_as_string {
1051- Ok ( batch) => format ! ( "DataFrame()\n {batch}" ) ,
1052- Err ( err) => format ! ( "Error: {:?}" , err. to_string( ) ) ,
1049+ let is_empty = batches. is_empty ( ) || batches. iter ( ) . all ( |b| b. num_rows ( ) == 0 ) ;
1050+ let result = if is_empty {
1051+ "Empty DataFrame" . to_string ( )
1052+ } else {
1053+ match pretty:: pretty_format_batches ( & batches) {
1054+ Ok ( batch) => format ! ( "DataFrame()\n {batch}" ) ,
1055+ Err ( err) => format ! ( "Error: {:?}" , err. to_string( ) ) ,
1056+ }
10531057 } ;
10541058
10551059 // Import the Python 'builtins' module to access the print function
You can’t perform that action at this time.
0 commit comments