@@ -72,16 +72,71 @@ use datafusion_ffi::table_provider::{FFI_TableProvider, ForeignTableProvider};
7272use pyo3:: types:: { PyCapsule , PyDict , PyList , PyTuple , PyType } ;
7373use tokio:: task:: JoinHandle ;
7474
75+ /// Configuration for displaying DataFrames
76+ #[ pyclass( name = "DataframeDisplayConfig" , module = "datafusion" , subclass) ]
77+ #[ derive( Clone ) ]
78+ pub struct DataframeDisplayConfig {
79+ /// Maximum bytes to display for table presentation (default: 2MB)
80+ #[ pyo3( get, set) ]
81+ pub max_table_bytes : usize ,
82+ /// Minimum number of table rows to display (default: 20)
83+ #[ pyo3( get, set) ]
84+ pub min_table_rows : usize ,
85+ /// Maximum length of a cell before it gets minimized (default: 25)
86+ #[ pyo3( get, set) ]
87+ pub max_cell_length : usize ,
88+ /// Maximum number of rows to display in repr string output (default: 10)
89+ #[ pyo3( get, set) ]
90+ pub max_table_rows_in_repr : usize ,
91+ }
92+
93+ #[ pymethods]
94+ impl DataframeDisplayConfig {
95+ #[ new]
96+ #[ pyo3( signature = ( max_table_bytes=None , min_table_rows=None , max_cell_length=None , max_table_rows_in_repr=None ) ) ]
97+ fn new (
98+ max_table_bytes : Option < usize > ,
99+ min_table_rows : Option < usize > ,
100+ max_cell_length : Option < usize > ,
101+ max_table_rows_in_repr : Option < usize > ,
102+ ) -> Self {
103+ let default = Self :: default ( ) ;
104+ Self {
105+ max_table_bytes : max_table_bytes. unwrap_or ( default. max_table_bytes ) ,
106+ min_table_rows : min_table_rows. unwrap_or ( default. min_table_rows ) ,
107+ max_cell_length : max_cell_length. unwrap_or ( default. max_cell_length ) ,
108+ max_table_rows_in_repr : max_table_rows_in_repr
109+ . unwrap_or ( default. max_table_rows_in_repr ) ,
110+ }
111+ }
112+ }
113+
114+ impl Default for DataframeDisplayConfig {
115+ fn default ( ) -> Self {
116+ Self {
117+ max_table_bytes : 2 * 1024 * 1024 , // 2 MB
118+ min_table_rows : 20 ,
119+ max_cell_length : 25 ,
120+ max_table_rows_in_repr : 10 ,
121+ }
122+ }
123+ }
124+
75125/// Configuration options for a SessionContext
76126#[ pyclass( name = "SessionConfig" , module = "datafusion" , subclass) ]
77127#[ derive( Clone , Default ) ]
78128pub struct PySessionConfig {
79129 pub config : SessionConfig ,
130+ #[ pyo3( get, set) ]
131+ pub display_config : DataframeDisplayConfig ,
80132}
81133
82134impl From < SessionConfig > for PySessionConfig {
83135 fn from ( config : SessionConfig ) -> Self {
84- Self { config }
136+ Self {
137+ config,
138+ display_config : DataframeDisplayConfig :: default ( ) ,
139+ }
85140 }
86141}
87142
@@ -97,7 +152,10 @@ impl PySessionConfig {
97152 }
98153 }
99154
100- Self { config }
155+ Self {
156+ config,
157+ display_config : DataframeDisplayConfig :: default ( ) ,
158+ }
101159 }
102160
103161 fn with_create_default_catalog_and_schema ( & self , enabled : bool ) -> Self {
0 commit comments