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
use std::borrow::Cow;
use thiserror::Error as ThisError;

type ErrString = Cow<'static, str>;

#[derive(Debug, ThisError)]
pub enum PolarsError {
    #[error(transparent)]
    PolarsArrowError(#[from] polars_arrow::error::PolarsError),
    #[error(transparent)]
    ArrowError(#[from] arrow::error::ArrowError),
    #[error("Invalid operation {0}")]
    InvalidOperation(ErrString),
    #[error("Data types don't match: {0}")]
    DataTypeMisMatch(ErrString),
    #[error("Not found: {0}")]
    NotFound(String),
    #[error("Lengths don't match: {0}")]
    ShapeMisMatch(ErrString),
    #[error("{0}")]
    ComputeError(ErrString),
    #[error("Out of bounds: {0}")]
    OutOfBounds(ErrString),
    #[error("Not contiguous or null values")]
    NoSlice,
    #[error("Such empty...: {0}")]
    NoData(ErrString),
    #[error("Invalid value: {0}")]
    ValueError(ErrString),
    #[error("Memory should be 64 byte aligned")]
    MemoryNotAligned,
    #[cfg(feature = "random")]
    #[error("{0}")]
    RandError(String),
    #[error("This operation requires data without Null values")]
    HasNullValues(ErrString),
    #[error("{0}")]
    UnknownSchema(ErrString),
    #[error(transparent)]
    Various(#[from] anyhow::Error),
    #[error(transparent)]
    Io(#[from] std::io::Error),
    #[error(transparent)]
    #[cfg(any(feature = "strings", feature = "temporal"))]
    Regex(#[from] regex::Error),
    #[error("DuplicateError: {0}")]
    Duplicate(ErrString),
    #[error("implementation error; this should not have happened.")]
    ImplementationError,
}

pub type Result<T> = std::result::Result<T, PolarsError>;
pub use arrow::error::ArrowError;