Skip to content

Commit a9178fe

Browse files
committed
feat: add FormatterConfig for configurable DataFrame display options
1 parent 4d8fa38 commit a9178fe

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/dataframe.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,62 @@ impl PyTableProvider {
7171
PyTable::new(table_provider)
7272
}
7373
}
74+
75+
/// Configuration for DataFrame display formatting
76+
#[derive(Debug, Clone)]
77+
pub struct FormatterConfig {
78+
/// Maximum memory in bytes to use for display (default: 2MB)
79+
pub max_bytes: usize,
80+
/// Minimum number of rows to display (default: 20)
81+
pub min_rows: usize,
82+
/// Number of rows to include in __repr__ output (default: 10)
83+
pub repr_rows: usize,
84+
}
85+
86+
impl Default for FormatterConfig {
87+
fn default() -> Self {
88+
Self {
89+
max_bytes: 2 * 1024 * 1024, // 2MB
90+
min_rows: 20,
91+
repr_rows: 10,
92+
}
93+
}
94+
}
95+
96+
// Keep constants for backward compatibility
7497
const MAX_TABLE_BYTES_TO_DISPLAY: usize = 2 * 1024 * 1024; // 2 MB
7598
const MIN_TABLE_ROWS_TO_DISPLAY: usize = 20;
7699

100+
fn get_formatter_config(py: Python) -> PyResult<FormatterConfig> {
101+
let formatter_module = py.import("datafusion.html_formatter")?;
102+
let get_formatter = formatter_module.getattr("get_formatter")?;
103+
let formatter = get_formatter.call0()?;
104+
105+
// Get max_memory_bytes (or fallback to default)
106+
let max_bytes = formatter
107+
.getattr("max_memory_bytes")
108+
.and_then(|v| v.extract::<usize>())
109+
.unwrap_or(FormatterConfig::default().max_bytes);
110+
111+
// Get min_rows_display (or fallback to default)
112+
let min_rows = formatter
113+
.getattr("min_rows_display")
114+
.and_then(|v| v.extract::<usize>())
115+
.unwrap_or(FormatterConfig::default().min_rows);
116+
117+
// Get repr_rows (or fallback to default)
118+
let repr_rows = formatter
119+
.getattr("repr_rows")
120+
.and_then(|v| v.extract::<usize>())
121+
.unwrap_or(FormatterConfig::default().repr_rows);
122+
123+
Ok(FormatterConfig {
124+
max_bytes,
125+
min_rows,
126+
repr_rows,
127+
})
128+
}
129+
77130
/// A PyDataFrame is a representation of a logical plan and an API to compose statements.
78131
/// Use it to build a plan and `.collect()` to execute the plan and collect the result.
79132
/// The actual execution of a plan runs natively on Rust and Arrow on a multi-threaded environment.

0 commit comments

Comments
 (0)