Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/dsl/functions/mod.rs
8427 views
1
//! # Functions
2
//!
3
//! Functions on expressions that might be useful.
4
#[cfg(feature = "business")]
5
mod business;
6
#[cfg(feature = "dtype-struct")]
7
mod coerce;
8
mod concat;
9
#[cfg(feature = "cov")]
10
mod correlation;
11
pub(crate) mod horizontal;
12
#[cfg(any(feature = "range", feature = "arg_where"))]
13
mod index;
14
#[cfg(feature = "range")]
15
mod range;
16
mod repeat;
17
mod selectors;
18
mod syntactic_sugar;
19
#[cfg(feature = "temporal")]
20
mod temporal;
21
22
pub use arity::*;
23
#[cfg(all(feature = "business", feature = "dtype-date"))]
24
pub use business::business_day_count;
25
#[cfg(feature = "dtype-struct")]
26
pub use coerce::*;
27
pub use concat::*;
28
#[cfg(feature = "cov")]
29
pub use correlation::*;
30
pub use horizontal::{
31
all_horizontal, any_horizontal, coalesce, fold_exprs, max_horizontal, mean_horizontal,
32
min_horizontal, reduce_exprs, sum_horizontal,
33
};
34
#[cfg(feature = "dtype-struct")]
35
pub use horizontal::{cum_fold_exprs, cum_reduce_exprs};
36
#[cfg(any(feature = "range", feature = "arg_where"))]
37
pub use index::*;
38
#[cfg(all(
39
feature = "range",
40
any(feature = "dtype-date", feature = "dtype-datetime")
41
))]
42
pub use range::date_range; // This shouldn't be necessary, but clippy complains about dead code
43
#[cfg(all(feature = "range", feature = "dtype-time"))]
44
pub use range::time_range; // This shouldn't be necessary, but clippy complains about dead code
45
#[cfg(feature = "range")]
46
pub use range::*;
47
pub use repeat::*;
48
pub use selectors::*;
49
pub use syntactic_sugar::*;
50
#[cfg(feature = "temporal")]
51
pub use temporal::*;
52
53
#[cfg(feature = "arg_where")]
54
use crate::dsl::function_expr::FunctionExpr;
55
use crate::dsl::function_expr::ListFunction;
56
#[cfg(all(feature = "concat_str", feature = "strings"))]
57
use crate::dsl::function_expr::StringFunction;
58
use crate::dsl::*;
59
60
/// Return the number of rows in the context.
61
pub fn len() -> Expr {
62
Expr::Len
63
}
64
65
/// First column in a DataFrame.
66
pub fn first() -> Selector {
67
nth(0)
68
}
69
70
/// Last column in a DataFrame.
71
pub fn last() -> Selector {
72
nth(-1)
73
}
74
75
/// Nth column in a DataFrame.
76
pub fn nth(n: i64) -> Selector {
77
Selector::ByIndex {
78
indices: [n].into(),
79
strict: true,
80
}
81
}
82
83
/// Create a Literal Expression from `L`. A literal expression behaves like a column that contains a single distinct
84
/// value.
85
///
86
/// The column is automatically of the "correct" length to make the operations work. Often this is determined by the
87
/// length of the `LazyFrame` it is being used with. For instance, `lazy_df.with_column(lit(5).alias("five"))` creates a
88
/// new column named "five" that is the length of the Dataframe (at the time `collect` is called), where every value in
89
/// the column is `5`.
90
pub fn lit<L: Literal>(t: L) -> Expr {
91
t.lit()
92
}
93
94