docs.rs failed to build polars-lazy-0.24.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
polars-lazy-0.43.1
Lazy API of Polars
*Credits to the work of Andy Grove and Ballista/ DataFusion / Apache Arrow, which served as
inspiration for the lazy API.*
The lazy api of Polars supports a subset of the eager api. Apart from the distributed compute,
it is very similar to [Apache Spark](https://spark.apache.org/). You write queries in a
domain specific language. These queries translate to a logical plan, which represent your query steps.
Before execution this logical plan is optimized and may change the order of operations if this will increase performance.
Or implicit type casts may be added such that execution of the query won't lead to a type error (if it can be resolved).
# Lazy DSL
The lazy API of polars can be used as long we operation on one or multiple DataFrame(s) and
Series of the same length as the DataFrame. To get started we call the [lazy](crate::frame::IntoLazy::lazy)
method. This returns a [LazyFrame](crate::frame::LazyFrame) exposing the lazy API.
Lazy operations don't execute until we call [collect](crate::frame::LazyFrame::collect).
This allows polars to optimize/reorder the query which may lead to faster queries or less type errors.
The DSL is mostly defined by [LazyFrame](crate::frame::LazyFrame) for operations on DataFrames and
the [Expr](crate::dsl::Expr) and functions in the [dsl modules](crate::dsl) that operate
on expressions.
## Examples
#### Adding a new column to a lazy DataFrame
```rust
#[macro_use] extern crate polars_core;
use polars_core::prelude::*;
use polars_lazy::prelude::*;
let df = df! {
"column_a" => &[1, 2, 3, 4, 5],
"column_b" => &["a", "b", "c", "d", "e"]
}.unwrap();
let new = df.lazy()
// Note the reverse here!!
.reverse()
.with_column(
// always rename a new column
(col("column_a") * lit(10)).alias("new_column")
)
.collect()
.unwrap();
assert!(new.column("new_column")
.unwrap()
.series_equal(
&Series::new("new_column", &[50, 40, 30, 20, 10])
)
);
```
#### Modifying a column based on some predicate
```rust
#[macro_use] extern crate polars_core;
use polars_core::prelude::*;
use polars_lazy::prelude::*;
let df = df! {
"column_a" => &[1, 2, 3, 4, 5],
"column_b" => &["a", "b", "c", "d", "e"]
}.unwrap();
let new = df.lazy()
.with_column(
// value = 100 if x < 3 else x
when(
col("column_a").lt(lit(3))
).then(
lit(100)
).otherwise(
col("column_a")
).alias("new_column")
)
.collect()
.unwrap();
assert!(new.column("new_column")
.unwrap()
.series_equal(
&Series::new("new_column", &[100, 100, 3, 4, 5])
)
);
```
#### Groupby + Aggregations
```rust
use polars_core::prelude::*;
use polars_core::df;
use polars_lazy::prelude::*;
use polars_arrow::prelude::QuantileInterpolOptions;
fn example() -> PolarsResult