Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-error/src/python.rs
6939 views
1
use pyo3::Python;
2
3
use crate::PolarsError;
4
5
pub struct PyErrWrap(pub pyo3::PyErr);
6
7
impl From<pyo3::PyErr> for PolarsError {
8
fn from(value: pyo3::PyErr) -> Self {
9
PolarsError::Python {
10
error: PyErrWrap(value),
11
}
12
}
13
}
14
15
impl Clone for PyErrWrap {
16
fn clone(&self) -> Self {
17
Python::with_gil(|py| Self(self.0.clone_ref(py)))
18
}
19
}
20
21
impl std::fmt::Debug for PyErrWrap {
22
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23
std::fmt::Debug::fmt(&self.0, f)
24
}
25
}
26
27
impl std::fmt::Display for PyErrWrap {
28
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29
std::fmt::Display::fmt(&self.0, f)
30
}
31
}
32
33
impl std::ops::Deref for PyErrWrap {
34
type Target = pyo3::PyErr;
35
36
fn deref(&self) -> &Self::Target {
37
&self.0
38
}
39
}
40
41
impl std::ops::DerefMut for PyErrWrap {
42
fn deref_mut(&mut self) -> &mut Self::Target {
43
&mut self.0
44
}
45
}
46
47