1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use anyhow::Error;
use std::borrow::Cow;
use thiserror::Error as ThisError;
type ErrString = Cow<'static, str>;
#[derive(Debug, ThisError)]
pub enum PolarsError {
#[error(transparent)]
ArrowError(Box<ArrowError>),
#[error("Invalid operation {0}")]
InvalidOperation(ErrString),
#[error("Data types don't match: {0}")]
SchemaMisMatch(ErrString),
#[error("Not found: {0}")]
NotFound(String),
#[error("Lengths don't match: {0}")]
ShapeMisMatch(ErrString),
#[error("{0}")]
ComputeError(ErrString),
#[error("Such empty...: {0}")]
NoData(ErrString),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("DuplicateError: {0}")]
Duplicate(ErrString),
}
impl From<ArrowError> for PolarsError {
fn from(err: ArrowError) -> Self {
Self::ArrowError(Box::new(err))
}
}
impl From<anyhow::Error> for PolarsError {
fn from(err: Error) -> Self {
PolarsError::ComputeError(format!("{:?}", err).into())
}
}
impl From<polars_arrow::error::PolarsError> for PolarsError {
fn from(err: polars_arrow::error::PolarsError) -> Self {
PolarsError::ComputeError(format!("{:?}", err).into())
}
}
#[cfg(any(feature = "strings", feature = "temporal"))]
impl From<regex::Error> for PolarsError {
fn from(err: regex::Error) -> Self {
PolarsError::ComputeError(format!("regex error: {:?}", err).into())
}
}
pub type Result<T> = std::result::Result<T, PolarsError>;
pub use arrow::error::ArrowError;