polars_rows_iter/lib.rs
1//! # Polars rows iterator
2//!
3//! Simple and convenient iteration of polars dataframe rows.
4//!
5//! ##### Example: Dataframe without None/null values:
6//! ```rust
7//!use polars::prelude::*;
8//!use polars_rows_iter::*;
9//!
10//!fn main() {
11//! #[derive(Debug, FromDataFrameRow)]
12//! #[derive(PartialEq)] // for assert_eq
13//! struct MyRow<'a>
14//! {
15//! #[column("col_a")]
16//! a: i32,
17//! // the column name defaults to the field name if no explicit name given
18//! col_b: &'a str,
19//! col_c: String,
20//! #[column("col_d")]
21//! optional: Option<f64>
22//! }
23//!
24//! let df = df!(
25//! "col_a" => [1i32, 2, 3, 4, 5],
26//! "col_b" => ["a", "b", "c", "d", "e"],
27//! "col_c" => ["A", "B", "C", "D", "E"],
28//! "col_d" => [Some(1.0f64), None, None, Some(2.0), Some(3.0)]
29//! ).unwrap();
30//!
31//! let rows_iter = df.rows_iter::<MyRow>().unwrap(); // ready to use row iterator
32//! // collect to vector for assert_eq
33//! let rows_vec = rows_iter.collect::<PolarsResult<Vec<MyRow>>>().unwrap();
34//!
35//! assert_eq!(
36//! rows_vec,
37//! [
38//! MyRow { a: 1, col_b: "a", col_c: "A".to_string(), optional: Some(1.0) },
39//! MyRow { a: 2, col_b: "b", col_c: "B".to_string(), optional: None },
40//! MyRow { a: 3, col_b: "c", col_c: "C".to_string(), optional: None },
41//! MyRow { a: 4, col_b: "d", col_c: "D".to_string(), optional: Some(2.0) },
42//! MyRow { a: 5, col_b: "e", col_c: "E".to_string(), optional: Some(3.0) },
43//! ]
44//! );
45//!}
46//! ```
47//! Every row is wrapped with a PolarsError, in case of an unexpected null value the row creation fails and the iterator
48//! returns an Err(...) for the row. One can decide to cancel the iteration or to skip the affected row.
49//!
50//! ## Supported types
51//!
52//! |State|Rust Type|Supported Polars DataType|Feature Flag|
53//! |--|--|--|--|
54//! |✓|`bool`|`Boolean`
55//! |✓|`u8`|`UInt8`
56//! |✓|`u16`|`UInt16`
57//! |✓|`u32`|`UInt32`
58//! |✓|`u64`|`UInt64`
59//! |✓|`i8`|`Int8`
60//! |✓|`i16`|`Int16`
61//! |✓|`i32`|`Int32`
62//! |✓|`i32`|`Date`
63//! |✓|`i64`|`Int64`
64//! |✓|`i64`|`Datetime(..)`
65//! |✓|`i64`|`Duration(..)`
66//! |✓|`i64`|`Time`
67//! |✓|`f32`|`Float32`
68//! |✓|`f64`|`Float64`
69//! |✓|`&str`|`String`
70//! |✓|`&str`|`Categorical(..)`|`dtype-categorical`
71//! |✓|`&str`|`Enum(..)`|`dtype-categorical`
72//! |✓|`String`|`String`
73//! |✓|`String`|`Categorical(..)`|`dtype-categorical`
74//! |✓|`String`|`Enum(..)`|`dtype-categorical`
75//! |✓|`&[u8]`|`Binary`
76//! |✓|`&[u8]`|`BinaryOffset`
77//! |✓|`Series`|`List(..)`
78//! |✓|`chrono::NaiveDateTime`|`Datetime(..)`|`chrono`
79//! |✓|`chrono::DateTime<Utc>`|`Datetime(..)`|`chrono`
80//! |✓|`chrono::Date`|`Date`|`chrono`|
81//! |?|?|`Array(..)`|
82//! |?|?|`Decimal(..)`|
83//! |?|?|`Struct(..)`|
84//! |X|X|`Null`
85//! |X|X|`Unknown(..)`|
86//! |X|X|`Object(..)`|
87//!
88//! TODO: Support is planned <br>
89//! ?: Support not yet certain<br>
90//! X: No Support
91
92mod dataframe_rows_iter_ext;
93mod from_dataframe_row;
94mod iter_from_column;
95
96pub use dataframe_rows_iter_ext::*;
97pub use from_dataframe_row::*;
98pub use iter_from_column::*;
99pub use polars_rows_iter_derive::FromDataFrameRow;
100
101#[cfg(test)]
102pub mod shared_test_helpers;