Skip to content

Commit aa87a8e

Browse files
committed
fix try_convert_to_string
1 parent 681b2e5 commit aa87a8e

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/dataframe.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl PyDataFrame {
9292

9393
#[pymethods]
9494
impl PyDataFrame {
95-
/// Enable selection for `df[col]`, `df[col1, col2, col3]`, and `df[[col1, col2, col3]]`
95+
/// Enable selection for `df[col]`, `df[col1, col2, col2]`, and `df[[col1, col2, col3]]`
9696
fn __getitem__(&self, key: Bound<'_, PyAny>) -> PyDataFusionResult<Self> {
9797
if let Ok(key) = key.extract::<PyBackedStr>() {
9898
// df[col]
@@ -998,16 +998,12 @@ fn try_extract_date(value: &PyObject, py: Python) -> Option<ScalarValue> {
998998

999999
/// Try to convert a Python object to string
10001000
fn try_convert_to_string(value: &PyObject, py: Python) -> PyDataFusionResult<ScalarValue> {
1001-
match value.str(py) {
1002-
Ok(py_str) => match py_str.to_string() {
1003-
Ok(s) => Ok(ScalarValue::Utf8(Some(s))),
1004-
Err(_) => {
1005-
let msg = "Failed to convert Python object to string";
1006-
Err(PyDataFusionError::Common(msg.to_string()))
1007-
}
1008-
},
1001+
// Try to convert arbitrary Python object to string by using str()
1002+
let str_result = value.call_method0(py, "str")?.extract::<String>(py);
1003+
match str_result {
1004+
Ok(string_value) => Ok(ScalarValue::Utf8(Some(string_value))),
10091005
Err(_) => {
1010-
let msg = "Unsupported Python type for fill_null";
1006+
let msg = "Could not convert Python object to string";
10111007
Err(PyDataFusionError::Common(msg.to_string()))
10121008
}
10131009
}

0 commit comments

Comments
 (0)