Skip to content

Commit ecc4376

Browse files
committed
refactor: move py_obj_to_scalar_value function to utils module
1 parent 0dfbdfa commit ecc4376

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/config.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use datafusion::common::ScalarValue;
2222
use datafusion::config::ConfigOptions;
2323

2424
use crate::errors::PyDataFusionResult;
25+
use crate::utils::py_obj_to_scalar_value;
2526

2627
#[pyclass(name = "Config", module = "datafusion", subclass)]
2728
#[derive(Clone)]
@@ -82,20 +83,3 @@ impl PyConfig {
8283
}
8384
}
8485
}
85-
86-
/// Convert a python object to a ScalarValue
87-
fn py_obj_to_scalar_value(py: Python, obj: PyObject) -> ScalarValue {
88-
if let Ok(value) = obj.extract::<bool>(py) {
89-
ScalarValue::Boolean(Some(value))
90-
} else if let Ok(value) = obj.extract::<i64>(py) {
91-
ScalarValue::Int64(Some(value))
92-
} else if let Ok(value) = obj.extract::<u64>(py) {
93-
ScalarValue::UInt64(Some(value))
94-
} else if let Ok(value) = obj.extract::<f64>(py) {
95-
ScalarValue::Float64(Some(value))
96-
} else if let Ok(value) = obj.extract::<String>(py) {
97-
ScalarValue::Utf8(Some(value))
98-
} else {
99-
panic!("Unsupported value type")
100-
}
101-
}

src/utils.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,20 @@ pub(crate) fn validate_pycapsule(capsule: &Bound<PyCapsule>, name: &str) -> PyRe
8787

8888
Ok(())
8989
}
90+
91+
/// Convert a python object to a ScalarValue
92+
pub(crate) fn py_obj_to_scalar_value(py: Python, obj: PyObject) -> ScalarValue {
93+
if let Ok(value) = obj.extract::<bool>(py) {
94+
ScalarValue::Boolean(Some(value))
95+
} else if let Ok(value) = obj.extract::<i64>(py) {
96+
ScalarValue::Int64(Some(value))
97+
} else if let Ok(value) = obj.extract::<u64>(py) {
98+
ScalarValue::UInt64(Some(value))
99+
} else if let Ok(value) = obj.extract::<f64>(py) {
100+
ScalarValue::Float64(Some(value))
101+
} else if let Ok(value) = obj.extract::<String>(py) {
102+
ScalarValue::Utf8(Some(value))
103+
} else {
104+
panic!("Unsupported value type")
105+
}
106+
}

0 commit comments

Comments
 (0)