Skip to content

Commit

Permalink
Merge pull request #2848 from finos/tkp/checkimp
Browse files Browse the repository at this point in the history
Check pyarrow import and make clear(er) error message
  • Loading branch information
texodus authored Nov 18, 2024
2 parents 456bd39 + 3eb8c70 commit 6d65d5f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rust/perspective-python/src/client/pandas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

use pyo3::exceptions::PyValueError;
use pyo3::exceptions::{PyImportError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::{PyAny, PyBytes, PyDict, PyList};

Expand Down Expand Up @@ -61,7 +61,15 @@ pub fn pandas_to_arrow_bytes<'py>(
py: Python<'py>,
df: &Bound<'py, PyAny>,
) -> PyResult<Bound<'py, PyBytes>> {
let pyarrow = PyModule::import_bound(py, "pyarrow")?;
let pyarrow = match PyModule::import_bound(py, "pyarrow") {
Ok(pyarrow) => pyarrow,
Err(_) => {
return Err(PyImportError::new_err(
"Perspective requires pyarrow to convert pandas DataFrames. Please install pyarrow.",
))
}
};

let df_class = get_pandas_df_cls(py)?
.ok_or_else(|| PyValueError::new_err("Failed to import pandas.DataFrame"))?;

Expand Down

0 comments on commit 6d65d5f

Please sign in to comment.