Skip to content

Commit 2e6b867

Browse files
committed
Include type name and cause in py_to_df conversion error
Addresses PR feedback: instead of a generic "Expected a pyarrow.Table or compatible type" message, include the actual Python type name and the underlying pyarrow error for easier debugging.
1 parent 3b4caf0 commit 2e6b867

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/lib.rs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ fn py_to_df(py: Python<'_>, obj: &Bound<'_, PyAny>) -> PyResult<DataFrame> {
6060
let table = if obj.is_instance(&pa.getattr("Table")?)? {
6161
obj.clone()
6262
} else {
63-
pa.call_method1("table", (obj,)).map_err(|_| {
64-
PyErr::new::<pyo3::exceptions::PyTypeError, _>(
65-
"Expected a pyarrow.Table or compatible type",
66-
)
63+
pa.call_method1("table", (obj,)).map_err(|e| {
64+
let type_name = obj
65+
.get_type()
66+
.name()
67+
.map(|n| n.to_string())
68+
.unwrap_or_else(|_| "<unknown>".to_string());
69+
PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
70+
"Expected a pyarrow.Table or compatible type, got {}: {}",
71+
type_name, e
72+
))
6773
})?
6874
};
6975

0 commit comments

Comments
 (0)