Skip to content

Commit d0209cf

Browse files
committed
refactor: simplify attribute extraction in get_formatter_config function
1 parent a9178fe commit d0209cf

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

src/dataframe.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,22 @@ fn get_formatter_config(py: Python) -> PyResult<FormatterConfig> {
102102
let get_formatter = formatter_module.getattr("get_formatter")?;
103103
let formatter = get_formatter.call0()?;
104104

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);
105+
// Helper function to extract attributes with fallback to default
106+
fn get_attr<'a>(
107+
formatter: &'a Bound<'a, PyAny>,
108+
attr_name: &str,
109+
default_value: usize,
110+
) -> usize {
111+
formatter
112+
.getattr(attr_name)
113+
.and_then(|v| v.extract::<usize>())
114+
.unwrap_or(default_value)
115+
}
116+
117+
let default_config = FormatterConfig::default();
118+
let max_bytes = get_attr(&formatter, "max_memory_bytes", default_config.max_bytes);
119+
let min_rows = get_attr(&formatter, "min_rows_display", default_config.min_rows);
120+
let repr_rows = get_attr(&formatter, "repr_rows", default_config.repr_rows);
122121

123122
Ok(FormatterConfig {
124123
max_bytes,

0 commit comments

Comments
 (0)