nodejs-polars
Version:
Polars: Blazingly fast DataFrames in Rust, Python, Node.js, R and SQL
1,605 lines • 59.6 kB
TypeScript
import * as dt from "./datetime";
import * as list from "./list";
import * as str from "./string";
import * as struct from "./struct";
export type { ExprDateTime as DatetimeNamespace } from "./datetime";
export type { ExprList as ListNamespace } from "./list";
export type { ExprString as StringNamespace } from "./string";
export type { ExprStruct as StructNamespace } from "./struct";
import type { DataType } from "../../datatypes";
import { Series } from "../../series";
import type { Arithmetic, Comparison, Cumulative, Deserialize, EwmOps, Rolling, Round, Sample, Serialize } from "../../shared_traits";
import type { FillNullStrategy, InterpolationMethod, RankMethod } from "../../types";
import { type ExprOrString, INSPECT_SYMBOL } from "../../utils";
/**
* Expressions that can be used in various contexts.
*/
export interface Expr extends Rolling<Expr>, Arithmetic<Expr>, Comparison<Expr>, Cumulative<Expr>, Sample<Expr>, Round<Expr>, EwmOps<Expr>, Serialize {
_expr: any;
get dt(): dt.ExprDateTime;
/**
* String namespace
*/
get str(): str.ExprString;
/**
* List namespace
* @deprecated *since 0.25.0 use list instead to match Polars core
*/
get lst(): list.ExprList;
get list(): list.ExprList;
/**
* Struct namespace
*/
get struct(): struct.ExprStruct;
[Symbol.toStringTag](): string;
[INSPECT_SYMBOL](): string;
toString(): string;
/** compat with `JSON.stringify` */
toJSON(): string;
/** Take absolute values */
abs(): Expr;
/**
* Rename the output of an expression.
* @param name new name
* @see {@link Expr.as}
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... });
* > df
* shape: (3, 2)
* ╭─────┬──────╮
* │ a ┆ b │
* │ --- ┆ --- │
* │ i64 ┆ str │
* ╞═════╪══════╡
* │ 1 ┆ "a" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ null │
* ╰─────┴──────╯
* > df.select([
* ... pl.col("a").alias("bar"),
* ... pl.col("b").alias("foo"),
* ... ])
* shape: (3, 2)
* ╭─────┬──────╮
* │ bar ┆ foo │
* │ --- ┆ --- │
* │ i64 ┆ str │
* ╞═════╪══════╡
* │ 1 ┆ "a" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ null │
* ╰─────┴──────╯
*```
*/
alias(name: string): Expr;
/**
Method equivalent of bitwise "and" operator `expr & other & ...`.
This has the effect of combining logical boolean expressions, but operates bitwise on integers.
@param other One or more integer or boolean expressions to evaluate/combine.
@example
```
const df = pl.DataFrame({ a: [1, 2, 3], b: [4, 5, 6] },{ schema: { a: pl.Int16, b: pl.Int16 } },);
df.select(pl.col("a").and(pl.col("b")).alias("a_and_b"));
shape: (3, 1)
┌────────┐
│ a_or_b │
│ --- │
│ i16 │
╞════════╡
│ 0 │
│ 0 │
│ 2 │
└────────┘
```
*/
and(other: any): Expr;
/**
* Check if all boolean values in the column are `true`.
* @param ignoreNulls - If `true` (default), null values are ignored. If `false`, any null is propagated and the result will be null if nulls are present.
* @returns Boolean expression.
* @example
* ```
* >>> const df = pl.DataFrame({ a: [true, true, null], b: [true, false, true] });
* >>> df.select(pl.col("a").all())
* shape: (1, 1)
* ┌──────┐
* │ a │
* │ --- │
* │ bool │
* ╞══════╡
* │ true │
* └──────┘
* >>> df.select(pl.col("b").all())
* shape: (1, 1)
* ┌───────┐
* │ b │
* │ --- │
* │ bool │
* ╞═══════╡
* │ false │
* └───────┘
* ```
*/
all(ignoreNulls?: boolean): Expr;
all({ ignoreNulls }: {
ignoreNulls?: boolean;
}): Expr;
/**
* Check if any boolean value in the column is `true`.
* @param ignoreNulls - If `true` (default), null values are ignored. If `false`, any null is propagated and the result will be null if nulls are present.
* @returns Boolean expression.
* @example
* ```
* >>> const df = pl.DataFrame({ a: [false, false, null], b: [false, true, false] });
* >>> df.select(pl.col("a").any())
* shape: (1, 1)
* ┌───────┐
* │ a │
* │ --- │
* │ bool │
* ╞═══════╡
* │ false │
* └───────┘
* >>> df.select(pl.col("b").any())
* shape: (1, 1)
* ┌──────┐
* │ b │
* │ --- │
* │ bool │
* ╞══════╡
* │ true │
* └──────┘
* ```
*/
any(ignoreNulls?: boolean): Expr;
any({ ignoreNulls }: {
ignoreNulls?: boolean;
}): Expr;
/**
* Compute the element-wise value for the inverse cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").acrcos())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.570796 │
└──────────┘
* ```
*/
arccos(): Expr;
/**
Compute two argument arctan in radians.
Returns the angle (in radians) in the plane between the positive x-axis and the ray from the origin to (x,y).
* @param other Expression, column name, or literal used as the `x` component.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"y": [1.0, 1.0], "x": [1.0, -1.0]})
>>> df.select(pl.col("y").arctan2("x").alias("angle"))
shape: (2, 1)
┌──────────┐
│ angle │
│ --- │
│ f64 │
╞══════════╡
│ 0.785398 │
│ 2.356194 │
└──────────┘
* ```
*/
arctan2(other: any): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrcosh())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │
└─────┘
* ```
*/
arccosh(): Expr;
/**
* Compute the element-wise value for the inverse sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrsin())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.570796 │
└──────────┘
* ```
*/
arcsin(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrsinh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.881374 │
└──────────┘
* ```
*/
arcsinh(): Expr;
/**
* Compute the element-wise value for the inverse tangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").arctan())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.785398 │
└──────────┘
* ```
*/
arctan(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic tangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").arctanh())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ inf │
└─────┘
* ```
*/
arctanh(): Expr;
/** Get the index of the maximal value. */
argMax(): Expr;
/** Get the index of the minimal value. */
argMin(): Expr;
/**
* Get the index values that would sort this column.
* @param descending Sort in descending (descending) order. Deault false
@param nullsLast Place null values last instead of first. Deault false
* @returns Expression of data type :class:`UInt32`
*/
argSort(descending?: boolean, nullsLast?: boolean): Expr;
argSort({ descending, nullsLast, }: {
descending?: boolean;
nullsLast?: boolean;
}): Expr;
/** Get index of first unique value. */
argUnique(): Expr;
/** @see {@link Expr.alias} */
as(name: string): Expr;
/** Fill missing values with the next to be seen values */
backwardFill(): Expr;
/** Cast between data types. */
cast(dtype: DataType, strict?: boolean): Expr;
/** Rounds up to the nearest integer value. Only works on floating point Series. */
ceil(): Expr;
/**
* Clip (limit) the values in an array to a `min` and `max` boundary.
*
* Only works for numerical types.
* @param min Minimum value.
* @param max Maximum value.
*/
clip(min: number, max: number): Expr;
clip(options: {
min: number;
max: number;
}): Expr;
/**
* Compute the element-wise value for the cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").cos())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 1.0 │
└─────┘
* ```
*/
cos(): Expr;
/**
* Compute the element-wise value for the hyperbolic cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").cosh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.543081 │
└──────────┘
* ```
*/
cosh(): Expr;
/**
* Compute the element-wise value for the cotangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").cot().round(2))
shape: (1, 1)
┌──────┐
│ a │
│ --- │
│ f64 │
╞══════╡
│ 0.64 │
└──────┘
* ```
*/
cot(): Expr;
/** Count the number of values in this expression */
count(): Expr;
/** Calculate the first discrete difference between shifted items.
* @param n number of slots to shift
* @param nullBehavior How to handle null values. ignore or drop
* @example
* ```
* const df = pl.DataFrame({"int": [20, 10, 30, 25, 35]})
* df.withColumns(pl.col("int").diff())
shape: (5, 2)
┌─────┬────────┐
│ int ┆ change │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪════════╡
│ 20 ┆ null │
│ 10 ┆ -10 │
│ 30 ┆ 20 │
│ 25 ┆ -5 │
│ 35 ┆ 10 │
└─────┴────────┘
>>> df.withColumns(pl.col("int").diff(n=2))
shape: (5, 2)
┌─────┬────────┐
│ int ┆ change │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪════════╡
│ 20 ┆ null │
│ 10 ┆ null │
│ 30 ┆ 10 │
│ 25 ┆ 15 │
│ 35 ┆ 5 │
└─────┴────────┘
>>> df.select(pl.col("int").diff(2,"drop").alias("diff"))
shape: (3, 1)
┌──────┐
│ diff │
│ --- │
│ i64 │
╞══════╡
│ 10 │
│ 15 │
│ 5 │
└──────┘
* ```
*/
diff(n: number, nullBehavior: "ignore" | "drop"): Expr;
diff(o: {
n: number;
nullBehavior: "ignore" | "drop";
}): Expr;
/** Convert an angle from radians to degrees, element-wise. */
degrees(): Expr;
/**
* Compute the dot/inner product between two Expressions
* @param other Expression to compute dot product with
*/
dot(other: any): Expr;
/** Drop NaN values from this expression. */
dropNans(): Expr;
/**
* Computes the entropy.
*
* Uses the formula `-sum(pk * log(pk))` where `pk` are discrete probabilities.
* @param base Given base, defaults to `e`
* @param normalize Normalize `pk` if it doesn't sum to 1.
* @example
* ```
* >>> const df = pl.DataFrame({"a": [0.0, 1.0, 2.0]})
* >>> df.select(pl.col("a").entropy({ base: 2 }))
* shape: (1, 1)
* ┌──────────┐
* │ a │
* │ --- │
* │ f64 │
* ╞══════════╡
* │ 1.459148 │
* └──────────┘
* ```
*/
entropy(base?: number, normalize?: boolean): Expr;
entropy(options: {
base?: number;
normalize?: boolean;
}): Expr;
/** Drop null values from this expression. */
dropNulls(): Expr;
/**
* Exclude certain columns from a wildcard/regex selection.
*
* You may also use regexes in the exclude list. They must start with `^` and end with `$`.
*
* @param columns Column(s) to exclude from selection
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... "c": [None, 2, 1],
* ...});
* > df
* shape: (3, 3)
* ╭─────┬──────┬──────╮
* │ a ┆ b ┆ c │
* │ --- ┆ --- ┆ --- │
* │ i64 ┆ str ┆ i64 │
* ╞═════╪══════╪══════╡
* │ 1 ┆ "a" ┆ null │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" ┆ 2 │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ null ┆ 1 │
* ╰─────┴──────┴──────╯
* > df.select(
* ... pl.col("*").exclude("b"),
* ... );
* shape: (3, 2)
* ╭─────┬──────╮
* │ a ┆ c │
* │ --- ┆ --- │
* │ i64 ┆ i64 │
* ╞═════╪══════╡
* │ 1 ┆ null │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ 2 │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ 1 │
* ╰─────┴──────╯
* ```
*/
exclude(column: string, ...columns: string[]): Expr;
/**
* Compute the exponential, element-wise.
* @example
* ```
>>> const df = pl.DataFrame({"values": [1.0, 2.0, 4.0]})
>>> df.select(pl.col("values").exp())
shape: (3, 1)
┌──────────┐
│ values │
│ --- │
│ f64 │
╞══════════╡
│ 2.718282 │
│ 7.389056 │
│ 54.59815 │
└──────────┘
* ```
*/
exp(): Expr;
/**
* Explode a list or utf8 Series.
*
* This means that every item is expanded to a new row.
*/
explode(): Expr;
/**
* Extend the Series with given number of values.
* @param value The value to extend the Series with. This value may be null to fill with nulls.
* @param n The number of values to extend.
*/
extendConstant(value: any, n: number): Expr;
extendConstant(opt: {
value: any;
n: number;
}): Expr;
/** Fill nan value with a fill value */
fillNan(other: any): Expr;
/**
* Fill null value with a fill value or strategy
* @param other - Fill value, expression, or one of the fill strategies
* ("backward", "forward", "mean", "min", "max", "zero", "one").
* @param limit - Number of consecutive null values to fill when using the
* "forward" or "backward" strategy.
*/
fillNull(other: any | FillNullStrategy, limit?: number): Expr;
/**
* Filter a single column.
*
* Mostly useful in in aggregation context.
* If you want to filter on a DataFrame level, use `LazyFrame.filter`.
* @param predicate Boolean expression.
*/
filter(predicate: Expr): Expr;
/** Get the first value. */
first(): Expr;
/** @see {@link Expr.explode} */
flatten(): Expr;
/** Rounds down to the nearest integer value. Only works on floating point Series. */
floor(): Expr;
/** Fill missing values with the latest seen values */
forwardFill(): Expr;
/**
* Take values by index.
* @param index An expression that leads to a UInt32 dtyped Series.
*/
gather(index: Expr | number[] | Series): Expr;
gather({ index }: {
index: Expr | number[] | Series;
}): Expr;
/** Take every nth value in the Series and return as a new Series. */
gatherEvery(n: number, offset?: number): Expr;
/** Hash the Series. */
hash(k0?: number, k1?: number, k2?: number, k3?: number): Expr;
hash({ k0, k1, k2, k3, }: {
k0?: number;
k1?: number;
k2?: number;
k3?: number;
}): Expr;
/**
* Apply a JavaScript function to each batch of values in a lazy expression.
*
* The function receives a {@link Series} for the current batch and must return a
* {@link Series} of the same length, or a scalar when `returnsScalar` is set. A
* returned scalar is broadcast across the batch.
*
* @param fn Lambda/function to apply.
* @param options Output dtype and streaming hints.
* @example
* ```
* > pl.DataFrame({ id: [10, 20, 30] })
* ... .lazy()
* ... .select(pl.col("id").mapBatches((s) => s.mul(2)).alias("id2"))
* ... .collect()
* shape: (3, 1)
* ┌──────┐
* │ id2 │
* │ --- │
* │ i64 │
* ╞══════╡
* │ 20 │
* ├╌╌╌╌╌╌┤
* │ 40 │
* ├╌╌╌╌╌╌┤
* │ 60 │
* ╰──────╯
* ```
*/
mapBatches(fn: (s: Series) => Series | MapBatchesScalar, options?: MapBatchesOptions): Expr;
mapBatches(options: {
fn: (s: Series) => Series | MapBatchesScalar;
} & MapBatchesOptions): Expr;
/** Take the first n values. */
head(length?: number): Expr;
head({ length }: {
length: number;
}): Expr;
/**
* Aggregate values into a list. The returned list itself is a scalar value of `list` dtype.
*
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... });
* > df
* shape: (3, 2)
* ╭─────┬──────╮
* │ a ┆ b │
* │ --- ┆ --- │
* │ i64 ┆ str │
* ╞═════╪══════╡
* │ 1 ┆ "a" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" │
* ├╌╌╌╌╌┼╌-╌╌╌╌┤
* │ 3 ┆ null │
* ╰─────┴──────╯
* > df.select(pl.col("a").implode())
* shape: (1, 1)
* ┌─────────────────┐
* │ a │
* │ --- │
* │ list[f64] │
* ╞═════════════════╡
* │ [1.0, 2.0, 3.0] │
* └─────────────────┘
* ```
*/
implode(): Expr;
inner(): any;
/**
* Interpolate intermediate values.
* @param method Interpolation method, either `"linear"` (default) or `"nearest"`.
*/
interpolate(method?: InterpolationMethod): Expr;
/** Get mask of duplicated values. */
isDuplicated(): Expr;
/** Create a boolean expression returning `true` where the expression values are finite. */
isFinite(): Expr;
/** Get a mask of the first unique value. */
isFirstDistinct(): Expr;
/**
* Check if elements of this Series are in the right Series, or List values of the right Series.
*
* @param other Series of primitive type or List type.
* @param nullsEquals default False, If True, treat null as a distinct value. Null values will not propagate.
* @returns Expr that evaluates to a Boolean Series.
* @example
* ```
* > const df = pl.DataFrame({
* ... "sets": [[1, 2, 3], [1, 2], [9, 10]],
* ... "optional_members": [1, 2, 3]
* ... });
* > df.select(
* ... pl.col("optional_members").isIn("sets").alias("contains")
* ... );
* shape: (3, 1)
* ┌──────────┐
* │ contains │
* │ --- │
* │ bool │
* ╞══════════╡
* │ true │
* ├╌╌╌╌╌╌╌╌╌╌┤
* │ true │
* ├╌╌╌╌╌╌╌╌╌╌┤
* │ false │
* └──────────┘
* ```
*/
isIn(other: any, nullsEquals?: boolean): Expr;
/** Create a boolean expression returning `true` where the expression values are infinite. */
isInfinite(): Expr;
/** Create a boolean expression returning `true` where the expression values are NaN (Not A Number). */
isNan(): Expr;
/** Create a boolean expression returning `true` where the expression values are not NaN (Not A Number). */
isNotNan(): Expr;
/** Create a boolean expression returning `true` where the expression does not contain null values. */
isNotNull(): Expr;
/** Create a boolean expression returning `True` where the expression contains null values. */
isNull(): Expr;
/** Get mask of unique values. */
isUnique(): Expr;
/**
* Keep the original root name of the expression.
*
* A groupby aggregation often changes the name of a column.
* With `keepName` we can keep the original name of the column
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... });
*
* > df
* ... .groupBy("a")
* ... .agg(pl.col("b").implode())
* ... .sort({by:"a"});
*
* shape: (3, 2)
* ╭─────┬────────────╮
* │ a ┆ b_agg_list │
* │ --- ┆ --- │
* │ i64 ┆ list [str] │
* ╞═════╪════════════╡
* │ 1 ┆ [a] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ [b] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ [null] │
* ╰─────┴────────────╯
*
* Keep the original column name:
*
* > df
* ... .groupby("a")
* ... .agg(col("b").implode().keepName())
* ... .sort({by:"a"})
*
* shape: (3, 2)
* ╭─────┬────────────╮
* │ a ┆ b │
* │ --- ┆ --- │
* │ i64 ┆ list [str] │
* ╞═════╪════════════╡
* │ 1 ┆ [a] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ [b] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ [null] │
* ╰─────┴────────────╯
* ```
*/
keepName(): Expr;
kurtosis(): Expr;
kurtosis(fisher: boolean, bias?: boolean): Expr;
kurtosis({ fisher, bias }: {
fisher?: boolean;
bias?: boolean;
}): Expr;
/** Get the last value. */
last(): Expr;
/***
* Compute the natural logarithm of each element plus one.
* This computes `log(1 + x)` but is more numerically stable for `x` close to zero.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select(pl.col("a").log1p())
shape: (3, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.693147 │
│ 1.098612 │
│ 1.386294 │
└──────────┘
* ```
*/
log1p(): Expr;
/**
* Compute the logarithm to a given base.
* @param base - Given base, defaults to `e`
* @example
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select(pl.col("a").log(base=2))
shape: (3, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.0 │
│ 1.0 │
│ 1.584963 │
└──────────┘
* ```
*/
log(base?: number): Expr;
/** Returns a unit Series with the lowest value possible for the dtype of this expression. */
lowerBound(): Expr;
peakMax(): Expr;
peakMin(): Expr;
/** Compute the max value of the arrays in the list */
max(): Expr;
/** Compute the mean value of the arrays in the list */
mean(): Expr;
/** Get median value. */
median(): Expr;
/** Get minimum value. */
min(): Expr;
/** Compute the most occurring value(s). Can return multiple Values */
mode(): Expr;
/** Negate a boolean expression. */
not(): Expr;
/** Count unique values. */
nUnique(): Expr;
/** Count null values.
@example
```
>>> const df = pl.DataFrame({"a": [null, 1, null], "b": [1, 2, null], "c": [1, 2, 3]});
>>> df.select(pl.col("a").nullCount())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ u32 │
╞═════╡
│ 2 │
└─────┘
```
*/
nullCount(): Expr;
/**
* Method equivalent of bitwise "or" operator `expr | other | ...`.
This has the effect of combining logical boolean expressions, but operates bitwise on integers.
@param other One or more expressions to combine with a bitwise "or".
@example
```
>>> const df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}, { schema: { a: pl.Int16, b: pl.Int16 } });
>>> df.select(pl.col("a").or(pl.col("b")).alias("a_or_b"));
shape: (3, 1)
┌────────┐
│ a_or_b │
│ --- │
│ i16 │
╞════════╡
│ 5 │
│ 7 │
│ 7 │
└────────┘
```
*/
or(other: any): Expr;
/**
* Apply window function over a subgroup.
*
* This is similar to a groupby + aggregation + self join.
* Or similar to [window functions in Postgres](https://www.postgresql.org/docs/9.1/tutorial-window.html)
* @param partitionBy Column(s) to partition by.
*
* @example
* ```
* > const df = pl.DataFrame({
* ... "groups": [1, 1, 2, 2, 1, 2, 3, 3, 1],
* ... "values": [1, 2, 3, 4, 5, 6, 7, 8, 8],
* ... });
* > df.select(
* ... pl.col("groups").sum().over("groups")
* ... );
* ╭────────┬────────╮
* │ groups ┆ values │
* │ --- ┆ --- │
* │ i32 ┆ i32 │
* ╞════════╪════════╡
* │ 1 ┆ 16 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 1 ┆ 16 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 2 ┆ 13 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 2 ┆ 13 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ ... ┆ ... │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 1 ┆ 16 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 2 ┆ 13 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 3 ┆ 15 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 3 ┆ 15 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 1 ┆ 16 │
* ╰────────┴────────╯
* ```
*/
over(by: ExprOrString, ...partitionBy: ExprOrString[]): Expr;
/**
* Computes percentage change between values.
*
* Percentage change (as fraction) between current element and most-recent
* non-null element at least `n` period(s) before the current element.
*
* Computes the change from the previous row by default.
* @param n periods to shift for forming percent change.
* @example
* ```
* >>> const df = pl.DataFrame({"a": [10, 11, 12, null, 12]})
* >>> df.withColumns(pl.col("a").pctChange().alias("pct_change"))
* shape: (5, 2)
* ┌──────┬────────────┐
* │ a ┆ pct_change │
* │ --- ┆ --- │
* │ i64 ┆ f64 │
* ╞══════╪════════════╡
* │ 10 ┆ null │
* │ 11 ┆ 0.1 │
* │ 12 ┆ 0.090909 │
* │ null ┆ 0.0 │
* │ 12 ┆ 0.0 │
* └──────┴────────────┘
* ```
*/
pctChange(n?: number | Expr): Expr;
pctChange(options: {
n: number | Expr;
}): Expr;
/** Raise expression to the power of exponent. */
pow(exponent: number): Expr;
pow({ exponent }: {
exponent: number;
}): Expr;
/**
* Add a prefix the to root column name of the expression.
* @example
* ```
* > const df = pl.DataFrame({
* ... "A": [1, 2, 3, 4, 5],
* ... "fruits": ["banana", "banana", "apple", "apple", "banana"],
* ... "B": [5, 4, 3, 2, 1],
* ... "cars": ["beetle", "audi", "beetle", "beetle", "beetle"],
* ... });
* shape: (5, 4)
* ╭─────┬──────────┬─────┬──────────╮
* │ A ┆ fruits ┆ B ┆ cars │
* │ --- ┆ --- ┆ --- ┆ --- │
* │ i64 ┆ str ┆ i64 ┆ str │
* ╞═════╪══════════╪═════╪══════════╡
* │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ "banana" ┆ 4 ┆ "audi" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │
* ╰─────┴──────────┴─────┴──────────╯
* > df.select(
* ... pl.col("*").reverse().prefix("reverse_"),
* ... )
* shape: (5, 8)
* ╭───────────┬────────────────┬───────────┬──────────────╮
* │ reverse_A ┆ reverse_fruits ┆ reverse_B ┆ reverse_cars │
* │ --- ┆ --- ┆ --- ┆ --- │
* │ i64 ┆ str ┆ i64 ┆ str │
* ╞═══════════╪════════════════╪═══════════╪══════════════╡
* │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ "banana" ┆ 4 ┆ "audi" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │
* ╰───────────┴────────────────┴───────────┴──────────────╯
* ```
*/
prefix(prefix: string): Expr;
/**
Compute the product of an expression.
Notes
-----
If there are no non-null values, then the output is `1`.
If you would prefer empty products to return `None`, you can
use `pl.when(expr.count()>0).then(expr.product())` instead
of `expr.product()`.
@example
```
>>> df = pl.DataFrame({"a": [1, 2, 3]});
>>> df.select(pl.col("a").product());
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 6.0 │
└─────┘
```
*/
product(): Expr;
/**
* Get quantile value.
* @param quantile Quantile between 0.0 and 1.0.
* @param interpolation Interpolation method: one of `"nearest"` (default),
* `"higher"`, `"lower"`, `"midpoint"`, or `"linear"`.
*/
quantile(quantile: number | Expr, interpolation?: InterpolationMethod): Expr;
/** Convert an angle from degrees to radians, element-wise. */
radians(): Expr;
/**
* Assign ranks to data, dealing with ties appropriately.
* @param method : {'average', 'min', 'max', 'dense', 'ordinal', 'random'}
* @param descending - Rank in descending order.
* */
rank(method?: RankMethod, descending?: boolean): Expr;
rank({ method, descending }: {
method: string;
descending: boolean;
}): Expr;
reinterpret(signed?: boolean): Expr;
reinterpret({ signed }: {
signed: boolean;
}): Expr;
/**
* Repeat the elements in this Series `n` times by dictated by the number given by `by`.
* The elements are expanded into a `List`
* @param by Numeric column that determines how often the values will be repeated.
*
* The column will be coerced to UInt32. Give this dtype to make the coercion a no-op.
*/
repeatBy(by: Expr | string): Expr;
/**
* Replace values by different values.
* @param old - Value or sequence of values to replace.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
* @param new_ - Value or sequence of values to replace by.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
Length must match the length of `old` or have length 1.
* @param default_ - Set values that were not replaced to this value. If no default is specified,
(default), an error is raised if any values were not replaced.
Accepts expression input. Non-expression inputs are parsed as literals.
* @param returnDtype - The data type of the resulting expression. If set to `None` (default), the data type is determined automatically based on the other inputs.
@returns InvalidOperationError - If any non-null values in the original column were not replaced, and no `default` was specified.
* @see {@link replace}
* @example
* Replace a single value by another value. Values that were not replaced remain unchanged.
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 2, 3]});
>>> df.withColumns(pl.col("a").replace(2, 100).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 3 │
└─────┴──────────┘
* ```
* Replace multiple values by passing sequences to the `old` and `new_` parameters.
* ```
>>> df.withColumns(pl.col("a").replace([2, 3], [100, 200]).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
* Passing a mapping with replacements is also supported as syntactic sugar.
Specify a default to set all values that were not matched.
* ```
>>> const mapping = {2: 100, 3: 200};
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping, default_: -1, returnDtype: pl.Int64 }).alias("replaced");
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ -1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
Replacing by values of a different data type sets the return type based on
a combination of the `new_` data type and either the original data type or the
default data type if it was set.
* ```
>>> const df = pl.DataFrame({"a": ["x", "y", "z"]});
>>> const mapping = {"x": 1, "y": 2, "z": 3};
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping }).alias("replaced"));
shape: (3, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪══════════╡
│ x ┆ 1 │
│ y ┆ 2 │
│ z ┆ 3 │
└─────┴──────────┘
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping, default_: None }).alias("replaced"));
shape: (3, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════╪══════════╡
│ x ┆ 1 │
│ y ┆ 2 │
│ z ┆ 3 │
└─────┴──────────┘
* ```
Set the `returnDtype` parameter to control the resulting data type directly.
* ```
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping, returnDtype: pl.UInt8 }).alias("replaced"));
shape: (3, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ str ┆ u8 │
╞═════╪══════════╡
│ x ┆ 1 │
│ y ┆ 2 │
│ z ┆ 3 │
└─────┴──────────┘
* ```
* Expression input is supported for all parameters.
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 2, 3], "b": [1.5, 2.5, 5.0, 1.0]});
>>> df.withColumns(
... pl.col("a").replaceStrict({
... old: pl.col("a").max(),
... new_: pl.col("b").sum(),
... default_: pl.col("b"),
... }).alias("replaced")
... );
shape: (4, 3)
┌─────┬─────┬──────────┐
│ a ┆ b ┆ replaced │
│ --- ┆ --- ┆ --- │
│ i64 ┆ f64 ┆ f64 │
╞═════╪═════╪══════════╡
│ 1 ┆ 1.5 ┆ 1.5 │
│ 2 ┆ 2.5 ┆ 2.5 │
│ 2 ┆ 5.0 ┆ 5.0 │
│ 3 ┆ 1.0 ┆ 10.0 │
└─────┴─────┴──────────┘
* ```
*/
replaceStrict(old: Expr | string | number | (number | string)[], new_: Expr | string | number | (number | string)[], default_?: Expr | string | number | (number | string)[], returnDtype?: DataType): Expr;
replaceStrict({ old, new_, default_, returnDtype, }: {
old: unknown | Expr | string | number | (number | string)[];
new_?: Expr | string | number | (number | string)[];
default_?: Expr | string | number | (number | string)[];
returnDtype?: DataType;
}): Expr;
/**
* Replace the given values by different values of the same data type.
* @param old - Value or sequence of values to replace.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
* @param new_ - Value or sequence of values to replace by.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
Length must match the length of `old` or have length 1.
* @see {@link replaceStrict}
* @see {@link replace}
* @example
* Replace a single value by another value. Values that were not replaced remain unchanged.
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 2, 3]});
>>> df.withColumns(pl.col("a").replace(2, 100).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 3 │
└─────┴──────────┘
* ```
* Replace multiple values by passing sequences to the `old` and `new_` parameters.
* ```
>>> df.withColumns(pl.col("a").replace([2, 3], [100, 200]).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
* Passing a mapping with replacements is also supported as syntactic sugar.
Specify a default to set all values that were not matched.
* ```
>>> const mapping = {2: 100, 3: 200};
>>> df.withColumns(pl.col("a").replace({ old: mapping }).alias("replaced");
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ -1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
*/
replace(old: Expr | string | number | (number | string)[], new_: Expr | string | number | (number | string)[]): Expr;
replace({ old, new_, }: {
old: unknown | Expr | string | number | (number | string)[];
new_?: Expr | string | number | (number | string)[];
}): Expr;
/**
* Reshape this Expr to a flat Series or a Series of Lists.
* @param dims Tuple of the dimension sizes. If a `-1` is used in any of the
* dimensions, that dimension is inferred.
* @returns Expr. If a single dimension is given, results in an expression of
* the original data type. If a multiple dimensions are given, results in an
* expression of data type `List` with shape `dims`.
* @example
* ```
* >>> const df = pl.DataFrame({"foo": [1, 2, 3, 4, 5, 6, 7, 8, 9]})
* >>> df.select(pl.col("foo").reshape([3, 3]))
* shape: (3, 1)
* ┌───────────┐
* │ foo │
* │ --- │
* │ list[i64] │
* ╞═══════════╡
* │ [1, 2, 3] │
* │ [4, 5, 6] │
* │ [7, 8, 9] │
* └───────────┘
* ```
*/
reshape(dims: number[]): Expr;
/** Reverse the arrays in the list */
reverse(): Expr;
/**
* Shift the values by a given period and fill the parts that will be empty due to this operation
* @param periods number of places to shift (may be negative).
*/
shift(periods?: number): Expr;
shift({ periods }: {
periods: number;
}): Expr;
/**
* Shift the values by a given period and fill the parts that will be empty due to this operation
* @param periods Number of places to shift (may be negative).
* @param fillValue Fill null values with the result of this expression.
*/
shiftAndFill(periods: number, fillValue: number): Expr;
shiftAndFill({ periods, fillValue, }: {
periods: number;
fillValue: number;
}): Expr;
/**
* Shuffle the contents of this expression.
* @param seed Seed for the random number generator. If not set, a random
* seed is generated each time the shuffle is called.
*/
shuffle(seed?: number): Expr;
shuffle(options: {
seed?: number;
}): Expr;
/**
* Compute the element-wise value for the sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").sin())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │
└─────┘
*```
*/
sin(): Expr;
/**
* Compute the element-wise value for the hyperbolic sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").sinh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.175201 │
└──────────┘
*```
*/
sinh(): Expr;
/**
* Compute the sample skewness of a data set.
* For normally distributed data, the skewness should be about zero. For
* unimodal continuous distributions, a skewness value greater than zero means
* that there is more weight in the right tail of the distribution.
* ___
* @param bias If False, then the calculations are corrected for statistical bias.
*/
skew(bias?: boolean): Expr;
skew({ bias }: {
bias: boolean;
}): Expr;
/** Slice the Series. */
slice(offset: number | Expr, length: number | Expr): Expr;
slice({ offset, length, }: {
offset: number | Expr;
length: number | Expr;
}): Expr;
/**
* Sort this column. In projection/ selection context the whole column is sorted.
* @param descending
* * false -> order from small to large.
* * true -> order from large to small.
* @param nullsLast If true nulls are considered to be larger than any valid value
* @param maintainOrder Whether the order should be maintained if elements are equal.
*/
sort(descending?: boolean, nullsLast?: boolean, maintainOrder?: boolean): Expr;
sort({ descending, nullsLast, maintainOrder, }: {
descending?: boolean;
nullsLast?: boolean;
maintainOrder?: boolean;
}): Expr;
/**
* Sort this column by the ordering of another column, or multiple other columns.
In projection/ selection context the whole column is sorted.
If used in a groupby context, the groups are sorted.
Parameters
----------
@param by The column(s) used for sorting.
@param descending
false -> order from small to large.
true -> order from large to small.
*/
sortBy(by: ExprOrString[] | ExprOrString, descending?: boolean | boolean[]): Expr;
sortBy(options: {
by: ExprOrString[] | ExprOrString;
descending?: boolean | boolean[];
}): Expr;
/** Get standard deviation. */
std(): Expr;
/** Add a suffix the to root column name of the expression. */
suffix(suffix: string): Expr;
/**
* Get sum value.
* Dtypes in {Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues.
*/
sum(): Expr;
/** Take the last n values. */
tail(length?: number): Expr;
tail({ length }: {
length: number;
}): Expr;
/**
* Compute the element-wise value for the tangent.
* @returns Expression of data type :class:`Float64`.
* @example
*```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").tan().round(2))
shape: (1, 1)
┌──────┐
│ a │
│ --- │
│ f64 │
╞══════╡
│ 1.56 │
└──────┘
*```
*/
tan(): Expr;
/**
* Compute the element-wise value for the hyperbolic tangent.
* @returns Expression of data type :class:`Float64`.
* @example
*```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").tanh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.761594 │
└──────────┘
*```
*/
tanh(): Expr;
/**
* Get the unique values of this expression;
* @param maintainOrder Maintain order of data. This requires more work.
*/
unique(maintainOrder?: boolean): Expr;
unique(opt: {
maintainOrder: boolean;
}): Expr;
/** Count the number of occurrences for each unique value. */
uniqueCounts(): Expr;
/** Returns a unit Series with the highest value possible for the dtype of this expression. */
upperBound(): Expr;
/**
* Count unique values in this expression.
* @param sort Sort output by count in descending order.
* @param parallel Execute computation in parallel.
* @param name Name of the count/proportion field in the output struct.
* @param normalize If true, return relative frequencies.
*/
valueCounts(sort?: boolean, parallel?: boolean, name?: string, normalize?: boolean): Expr;
/** Get variance. */
var(): Expr;
/** Alias for filter: @see {@link filter} */
where(predicate: Expr): Expr;
/** Return the physical representation backing this expression's dtype. */
toPhysical(): Expr;
}
/** @ignore */
export declare const _Expr: (_expr: any) => Expr;
export interface ExprConstructor extends Deserialize<Expr> {
isExpr(arg: any): arg is Expr;
}
export declare const Expr: ExprConstructor;
export declare const exprToLitOrExpr: (expr: any, stringToLit?: boolean) => Expr;
type DateComponent = ExprOrString | number;
export interface DatetimeOptions {
/** Time unit of the resulting expression. */
timeUnit?: "ms" | "us" | "ns";
/** Time zone of the resulting expression. */
timeZone?: string | null;
/** How to handle ambiguous datetimes: `"earliest"`, `"latest"`, `"raise"`, or `"null"`. */
ambiguous?: ExprOrString;
}
export interface MapBatchesOptions {
/** Expected dtype of the returned series. */
returnType?: DataType;
/**
* Whether the UDF preserves one output row per input row within a batch.
* @default false
*/
isElementwise?: boolean;
/**
* Whether the UDF returns a single scalar value per batch, which is then
* broadcast across the batch. Mutually exclusive with `isElementwise`; when
* set, `isElementwise` is ignored.
* @default false
*/
returnsScalar?: boolean;
}
/** A scalar value a `mapBatches` callback may return when `returnsScalar` is set. */
export type MapBatchesScalar = number | bigint | string | boolean | Date | null | undefined;
/**
* Create an expression of type `Datetime` from its components.
*
* @param year Column or literal.
* @param month Column or literal, ranging from 1-12.
* @param day Column or literal, ranging from 1-31.
* @param hour Column or literal, ranging from 0-23.
* @param minute Column or literal, ranging from 0-59.
* @param second Column or literal, ranging from 0-59.
* @param microsecond Column or literal, ranging from 0-999999.
* @param options.timeUnit Time unit of the resulting expression.
* @param options.timeZone Time zone of the resulting expression.
* @param options.ambiguous How to handle ambiguous datetimes.
* @example
* ```
* > const df = pl.DataFrame({ month: [1, 2], day: [3, 4] });
* > df.select(pl.datetime(2024, pl.col("month"), pl.col("day")));
* shape: (2, 1)
* ┌────────────┐
* │ datetime │
* │ --- │
* │ datetime[μs] │
* ╞════════════╡
* │ 2024-01-03 │
* │ 2024-02-04 │
* └────────────┘
* ```
*/
export declare function datetime(year: DateComponent, month: DateComponent, day: DateComponent, hour?: DateComponent | DatetimeOptions | null, minute?: DateComponent | DatetimeOptions | null, second?: DateComponent | DatetimeOptions | null, microsecond?: DateComponent | DatetimeOptions | null, options?: DatetimeOptions): Expr;
/**
* Create an expression of type `Date` from its components.
*
* @param year Column or literal.
* @param month Column or literal, ranging from 1-12.
* @param day Column or literal, ranging from 1-31.
* @example
* ```
* > const df = pl.DataFrame({ month: [1, 2], day: [3, 4] });
* > df.select(pl.date(2024, pl.col("month"), pl.col("day")));
* shape: (2, 1)
* ┌────────────┐
* │ date │
* │ --- │
* │ date │
* ╞════════════╡
* │ 2024-01-03 │
* │ 2024-02-04 │
* └────────────┘
* ```
*/
export declare function date(year: DateComponent, month: DateComponent, day: DateComponent): Expr;
export interface DurationOptions {
/** Number of weeks. */
weeks?: DateComponent;
/** Number of days. */
days?: DateComponent;
/** Number of hours. */
hours?: DateComponent;
/** Number of minutes. */
minutes?: DateComponent;
/** Number of seconds. */
seconds?: DateComponent;
/** Number of milliseconds. */
milliseconds?: DateComponent;
/** Number of microseconds. */
microseconds?: DateComponent;
/** Number of nanoseconds. */
nanoseconds?: DateComponent;
/**
* Time unit of the resulting expression. Defaults to `"ns"` when
* `nanoseconds` is specified, and `"us"` otherwise.
*/
timeUnit?: "ms" | "us" | "ns";
}
/**
* Create an expression of type `Duration` from distinct time components.
*
* @param options Duration components and optional time unit.
* @example
* ```
* > const df = pl.DataFrame({ add: [1, 2] });
* > df.select(pl.duration({ days: pl.col("add") }));
* shape: (2, 1)
* ┌──────────────┐
* │ duration │
* │ --- │
* │ duration[μs] │
* ╞══════════════╡
* │ 1d │
* │ 2d │
* └──────────────┘
* ```
*/
export declare function duration(options?: DurationOptions): Expr;