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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//! # Polars: *<small>DataFrames in Rust</small>*
//!
//! Polars is a DataFrame library for Rust. It is based on [Apache Arrows](https://arrow.apache.org/) memory model.
//! This means that operations on Polars array's *(called `Series` or `ChunkedArray<T>` {if the type `T` is known})* are
//! optimally aligned cache friendly operations and SIMD. Sadly, Apache Arrow needs **nightly Rust**,
//! which means that Polars cannot run on stable.
//!
//! Polars supports an eager and a lazy api. The eager api is similar to [pandas](https://pandas.pydata.org/),
//! the lazy api is similar to [Spark](https://spark.apache.org/).
//!
//! ### Eager
//! Read more in the pages of the following data structures /traits.
//!
//! * [DataFrame struct](crate::frame::DataFrame)
//! * [Series struct](crate::series::Series)
//! * [Series trait](crate::series::SeriesTrait)
//! * [ChunkedArray struct](crate::chunked_array::ChunkedArray)
//!
//! ### Lazy
//! Read more in the [lazy](polars_lazy) module
//!
//! ## Read and write CSV/ JSON
//!
//! ```
//! use polars::prelude::*;
//! use std::fs::File;
//!
//! fn example() -> Result<DataFrame> {
//!     let file = File::open("iris.csv")
//!                     .expect("could not read file");
//!
//!     CsvReader::new(file)
//!             .infer_schema(None)
//!             .has_header(true)
//!             .finish()
//! }
//! ```
//!
//! For more IO examples see:
//!
//! * [the csv module](polars_io::csv)
//! * [the json module](polars_io::json)
//! * [the IPC module](polars_io::ipc)
//! * [the parquet module](polars_io::parquet)
//!
//! ## Joins
//!
//! ```
//! # #[macro_use] extern crate polars;
//! # fn main() {
//! use polars::prelude::*;
//!
//! fn join() -> Result<DataFrame> {
//!     // Create first df.
//!     let temp = df!("days" => &[0, 1, 2, 3, 4],
//!                    "temp" => &[22.1, 19.9, 7., 2., 3.])?;
//!
//!     // Create second df.
//!     let rain = df!("days" => &[1, 2],
//!                    "rain" => &[0.1, 0.2])?;
//!
//!     // Left join on days column.
//!     temp.left_join(&rain, "days", "days")
//! }
//!
//! println!("{}", join().unwrap())
//! # }
//! ```
//!
//! ```text
//! +------+------+------+
//! | days | temp | rain |
//! | ---  | ---  | ---  |
//! | i32  | f64  | f64  |
//! +======+======+======+
//! | 0    | 22.1 | null |
//! +------+------+------+
//! | 1    | 19.9 | 0.1  |
//! +------+------+------+
//! | 2    | 7    | 0.2  |
//! +------+------+------+
//! | 3    | 2    | null |
//! +------+------+------+
//! | 4    | 3    | null |
//! +------+------+------+
//! ```
//!
//! ## Groupby's | aggregations | pivots | melts
//!
//! ```
//! use polars::prelude::*;
//! fn groupby_sum(df: &DataFrame) -> Result<DataFrame> {
//!     df.groupby("column_name")?
//!     .select("agg_column_name")
//!     .sum()
//! }
//! ```
//!
//! ## Arithmetic
//! ```
//! use polars::prelude::*;
//! let s = Series::new("foo", [1, 2, 3]);
//! let s_squared = &s * &s;
//! ```
//!
//! ## Rust iterators
//!
//! ```
//! use polars::prelude::*;
//!
//! let s: Series = [1, 2, 3].iter().collect();
//! let s_squared: Series = s.i32()
//!      .expect("datatype mismatch")
//!      .into_iter()
//!      .map(|optional_v| {
//!          match optional_v {
//!              Some(v) => Some(v * v),
//!              None => None, // null value
//!          }
//!  }).collect();
//! ```
//!
//! ## Apply custom closures
//!
//! Besides running custom iterators, custom closures can be applied on the values of [ChunkedArray](chunked_array/struct.ChunkedArray.html)
//! by using the [apply](chunked_array/apply/trait.Apply.html) method. This method accepts
//! a closure that will be applied on all values of `Option<T>` that are non null. Note that this is the
//! **fastest** way to apply a custom closure on `ChunkedArray`'s.
//! ```
//! # use polars::prelude::*;
//! let s: Series = Series::new("values", [Some(1.0), None, Some(3.0)]);
//! // null values are ignored automatically
//! let squared = s.f64()
//!     .unwrap()
//!     .apply(|value| value.powf(2.0))
//!     .into_series();
//!
//! assert_eq!(Vec::from(squared.f64().unwrap()), &[Some(1.0), None, Some(9.0)])
//! ```
//!
//! ## Comparisons
//!
//! ```
//! use polars::prelude::*;
//! let s = Series::new("dollars", &[1, 2, 3]);
//! let mask = s.eq(1);
//!
//! assert_eq!(Vec::from(mask), &[Some(true), Some(false), Some(false)]);
//! ```
//!
//! ## Temporal data types
//!
//! ```rust
//! # use polars::prelude::*;
//! let dates = &[
//! "2020-08-21",
//! "2020-08-21",
//! "2020-08-22",
//! "2020-08-23",
//! "2020-08-22",
//! ];
//! // date format
//! let fmt = "%Y-%m-%d";
//! // create date series
//! let s0 = Date32Chunked::parse_from_str_slice("date", dates, fmt)
//!         .into_series();
//! ```
//!
//!
//! ## And more...
//!
//! * [DataFrame](crate::frame::DataFrame)
//! * [Series](crate::series::Series)
//! * [ChunkedArray](crate::chunked_array::ChunkedArray)
//!     - [Operations implemented by Traits](crate::chunked_array::ops)
//! * [Time/ DateTime utilities](crate::doc::time)
//! * [Groupby, aggregations, pivots and melts](crate::frame::group_by::GroupBy)
//!
//! ## Features
//!
//! Additional cargo features:
//!
//! * `temporal (default)`
//!     - Conversions between Chrono and Polars for temporal data
//! * `simd (default)`
//!     - SIMD operations
//! * `parquet`
//!     - Read Apache Parquet format
//! * `json`
//!     - Json serialization
//! * `ipc`
//!     - Arrow's IPC format serialization
//! * `random`
//!     - Generate array's with randomly sampled values
//! * `ndarray`
//!     - Convert from `DataFrame` to `ndarray`
//! * `parallel`
//!     - Parallel variants of operations
//! * `lazy`
//!     - Lazy api
//! * `strings`
//!     - String utilities for `Utf8Chunked`
//! * `object`
//!     - Support for generic ChunkedArray's called `ObjectChunked<T>` (generic over `T`).
//!       These will downcastable from Series through the [Any](https://doc.rust-lang.org/std/any/index.html) trait.
pub mod prelude;
pub use polars_core::{
    chunked_array, datatypes, doc, error, frame, functions, series, testing, toggle_string_cache,
};

pub use polars_core::apply_method_all_arrow_series;
pub use polars_core::df;

pub use polars_io as io;
#[cfg(feature = "lazy")]
pub use polars_lazy as lazy;