8000 refactor get_attr function to support generic default values · kosiew/datafusion-python@b52166b · GitHub
[go: up one dir, main page]

Skip to content

Commit b52166b

Browse files
committed
refactor get_attr function to support generic default values
1 parent 43a3183 commit b52166b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/dataframe.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,14 @@ fn import_python_formatter(py: Python) -> PyResult<Bound<'_, PyAny>> {
138138
get_formatter.call0()
139139
}
140140
// Helper function to extract attributes with fallback to default
141-
fn get_attr<'a>(py_object: &'a Bound<'a, PyAny>, attr_name: &str, default_value: usize) -> usize {
141+
fn get_attr<'a, T>(py_object: &'a Bound<'a, PyAny>, attr_name: &str, default_value: T) -> T
142+
where
143+
T: for<'py> pyo3::FromPyObject<'py> + Clone,
144+
{
142145
py_object
143146
.getattr(attr_name)
144-
.and_then(|v| v.extract::<usize>())
145-
.unwrap_or(default_value)
147+
.and_then(|v| v.extract::<T>())
148+
.unwrap_or_else(|_| default_value.clone())
146149
}
147150

148151
/// Helper function to create a FormatterConfig from a Python formatter object

0 commit comments

Comments
 (0)
0