Skip to content

Commit 17d54cd

Browse files
committed
feat: Enhance DisplayConfig for DataFrame with customizable options
- Added DisplayConfig struct for configuring DataFrame display in Python. - Introduced fields: max_table_bytes, min_table_rows, and max_cell_length with default values. - Implemented a constructor for DisplayConfig to allow optional customization. - Updated display_config method in PyDataFrame to return a Python object of DisplayConfig.
1 parent 41e6ad2 commit 17d54cd

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/dataframe.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,38 @@ impl PyTableProvider {
7474
}
7575

7676
/// Configuration for DataFrame display in Python environment
77+
#[pyclass(name = "DisplayConfig", module = "datafusion")]
7778
#[derive(Debug, Clone)]
7879
pub struct DisplayConfig {
7980
/// Maximum bytes to display for table presentation (default: 2MB)
81+
#[pyo3(get, set)]
8082
pub max_table_bytes: usize,
8183
/// Minimum number of table rows to display (default: 20)
84+
#[pyo3(get, set)]
8285
pub min_table_rows: usize,
8386
/// Maximum length of a cell before it gets minimized (default: 25)
87+
#[pyo3(get, set)]
8488
pub max_cell_length: usize,
8589
}
8690

91+
#[pymethods]
92+
impl DisplayConfig {
93+
#[new]
94+
#[pyo3(signature = (max_table_bytes=None, min_table_rows=None, max_cell_length=None))]
95+
fn new(
96+
max_table_bytes: Option<usize>,
97+
min_table_rows: Option<usize>,
98+
max_cell_length: Option<usize>,
99+
) -> Self {
100+
let default = DisplayConfig::default();
101+
Self {
102+
max_table_bytes: max_table_bytes.unwrap_or(default.max_table_bytes),
103+
min_table_rows: min_table_rows.unwrap_or(default.min_table_rows),
104+
max_cell_length: max_cell_length.unwrap_or(default.max_cell_length),
105+
}
106+
}
107+
}
108+
87109
impl Default for DisplayConfig {
88110
fn default() -> Self {
89111
Self {
@@ -823,8 +845,15 @@ impl PyDataFrame {
823845

824846
/// Get the current display configuration
825847
#[getter]
826-
fn display_config(&self) -> DisplayConfig {
827-
(*self.config).clone()
848+
fn display_config(&self) -> PyResult<Py<DisplayConfig>> {
849+
Python::with_gil(|py| {
850+
let config = DisplayConfig {
851+
max_table_bytes: self.config.max_table_bytes,
852+
min_table_rows: self.config.min_table_rows,
853+
max_cell_length: self.config.max_cell_length,
854+
};
855+
Py::new(py, config).map_err(PyErr::from)
856+
})
828857
}
829858

830859
/// Update display configuration

0 commit comments

Comments
 (0)