Generic expressions
Scalars and columns of any element type.
Value
Base class for a data generating expression having a known type.
Methods
Name | Description |
---|---|
asc | Sort an expression ascending. |
cast | Cast expression to indicated data type. |
coalesce | Return the first non-null value from args . |
collect | Aggregate this expression’s elements into an array. |
identical_to | Return whether this expression is identical to other. |
isin | Check whether this expression’s values are in values . |
isnull | Return whether this expression is NULL. |
name | Rename an expression to name . |
notnull | Return whether this expression is not NULL. |
nullif | Set values to null if they equal the values null_if_expr . |
try_cast | Try cast expression to indicated data type. |
asc
Sort an expression ascending.
cast
Cast expression to indicated data type.
Similar to pandas.Series.astype
.
Parameters
Name | Type | Description | Default |
---|---|---|---|
target_type | Any | Type to cast to. Anything accepted by ibis.dtype() | required |
Returns
Name | Type | Description |
---|---|---|
Value | Casted expression |
See Also
Examples
python’s built-in types can be used
or string names
If you make an illegal cast, you won’t know until the backend actually
executes it. Consider
.try_cast()
.
coalesce
Return the first non-null value from args
.
Parameters
Name | Type | Description | Default |
---|---|---|---|
args | Value | Arguments from which to choose the first non-null value | () |
Returns
Name | Type | Description |
---|---|---|
Value | Coalesced expression |
See Also
ibis.coalesce()
Value.fill_null()
Examples
collect
Aggregate this expression’s elements into an array.
This function is called array_agg
, list_agg
, or list
in other
systems.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | An optional filter expression. If provided, only rows where where is True will be included in the aggregate. | None |
order_by | Any | An ordering key (or keys) to use to order the rows before aggregating. If not provided, the order of the items in the result is undefined and backend specific. | None |
include_null | bool | Whether to include null values when performing this aggregation. Set to True to include nulls in the result. | False |
Returns
Name | Type | Description |
---|---|---|
ArrayScalar | Collected array |
Examples
Basic collect usage
Collect elements per group
Collect elements per group using a filter
identical_to
Return whether this expression is identical to other.
Corresponds to IS NOT DISTINCT FROM
in SQL.
Parameters
Name | Type | Description | Default |
---|---|---|---|
other | Value | Expression to compare to | required |
Returns
Name | Type | Description |
---|---|---|
BooleanValue | Whether this expression is not distinct from other |
Examples
isin
Check whether this expression’s values are in values
.
NULL
values are propagated in the output. See examples for details.
Parameters
Name | Type | Description | Default |
---|---|---|---|
values | Value | Sequence[Value] | Values or expression to check for membership | required |
Returns
Name | Type | Description |
---|---|---|
BooleanValue | Expression indicating membership |
See Also
Examples
Check against a literal sequence of values
Check against a derived expression
Check against a column from a different table
NULL
behavior
isnull
Return whether this expression is NULL.
Examples
name
Rename an expression to name
.
Parameters
Name | Type | Description | Default |
---|---|---|---|
name | The new name of the expression | required |
Returns
Name | Type | Description |
---|---|---|
Value | self with name name |
Examples
notnull
Return whether this expression is not NULL.
Examples
nullif
Set values to null if they equal the values null_if_expr
.
Commonly used to avoid divide-by-zero problems by replacing zero with
NULL
in the divisor.
Equivalent to (self == null_if_expr).ifelse(ibis.null(), self)
.
Parameters
Name | Type | Description | Default |
---|---|---|---|
null_if_expr | Value | Expression indicating what values should be NULL | required |
Returns
Name | Type | Description |
---|---|---|
Value | Value expression |
Examples
try_cast
Try cast expression to indicated data type.
If the cast fails for a row, the value is returned as null or NaN depending on target_type and backend behavior.
Parameters
Name | Type | Description | Default |
---|---|---|---|
target_type | Any | Type to try cast to. Anything accepted by ibis.dtype() | required |
Returns
Name | Type | Description |
---|---|---|
Value | Casted expression |
See Also
Examples
Scalar
Methods
Name | Description |
---|---|
as_table | Promote the scalar expression to a table. |
as_table
Promote the scalar expression to a table.
Returns
Name | Type | Description |
---|---|---|
Table | A table expression |
Examples
Promote an aggregation to a table
Promote a literal value to a table
Column
Methods
Name | Description |
---|---|
approx_median | Return an approximate of the median of self . |
approx_nunique | Return the approximate number of distinct elements in self . |
arbitrary | Select an arbitrary value in a column. |
count | Compute the number of rows in an expression. |
first | Return the first value of a column. |
lag | Return the row located at offset rows before the current row. |
last | Return the last value of a column. |
lead | Return the row located at offset rows after the current row. |
max | Return the maximum of a column. |
median | Return the median of the column. |
min | Return the minimum of a column. |
nth | Return the n th value (0-indexed) over a window. |
nunique | Compute the number of distinct rows in an expression. |
approx_median
Return an approximate of the median of self
.
The result may or may not be exact. Whether the result is an approximation depends on the backend.
Do not depend on the results being exact
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Filter in values when where is True | None |
Returns
Name | Type | Description |
---|---|---|
Scalar | An approximation of the median of self |
Examples
approx_nunique
Return the approximate number of distinct elements in self
.
The result may or may not be exact. Whether the result is an approximation depends on the backend.
Do not depend on the results being exact
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Filter in values when where is True | None |
Returns
Name | Type | Description |
---|---|---|
Scalar | An approximate count of the distinct elements of self |
Examples
arbitrary
Select an arbitrary value in a column.
Returns an arbitrary (nondeterministic, backend-specific) value from the column. The value will be non-NULL, except if the column is empty or all values are NULL.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | A filter expression | None |
how | Any | DEPRECATED | None |
Returns
Name | Type | Description |
---|---|---|
Scalar | An expression |
Examples
count
Compute the number of rows in an expression.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Filter expression | None |
Returns
Name | Type | Description |
---|---|---|
IntegerScalar | Number of elements in an expression |
first
Return the first value of a column.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | An optional filter expression. If provided, only rows where where is True will be included in the aggregate. | None |
order_by | Any | An ordering key (or keys) to use to order the rows before aggregating. If not provided, the meaning of first is undefined and will be backend specific. | None |
include_null | bool | Whether to include null values when performing this aggregation. Set to True to include nulls in the result. | False |
Examples
lag
Return the row located at offset
rows before the current row.
Parameters
Name | Type | Description | Default |
---|---|---|---|
offset | int | ir.IntegerValue | None | Index of row to select | None |
default | Value | None | Value used if no row exists at offset | None |
last
Return the last value of a column.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | An optional filter expression. If provided, only rows where where is True will be included in the aggregate. | None |
order_by | Any | An ordering key (or keys) to use to order the rows before aggregating. If not provided, the meaning of last is undefined and will be backend specific. | None |
include_null | bool | Whether to include null values when performing this aggregation. Set to True to include nulls in the result. | False |
Examples
lead
Return the row located at offset
rows after the current row.
Parameters
Name | Type | Description | Default |
---|---|---|---|
offset | int | ir.IntegerValue | None | Index of row to select | None |
default | Value | None | Value used if no row exists at offset | None |
max
Return the maximum of a column.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Filter in values when where is True | None |
Returns
Name | Type | Description |
---|---|---|
Scalar | The maximum value in self |
Examples
median
Return the median of the column.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Optional boolean expression. If given, only the values where where evaluates to true will be considered for the median. | None |
Returns
Name | Type | Description |
---|---|---|
Scalar | Median of the column |
Examples
Compute the median of bill_depth_mm
In addition to numeric types, any orderable non-numeric types such as
strings and dates work with median
.
min
Return the minimum of a column.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Filter in values when where is True | None |
Returns
Name | Type | Description |
---|---|---|
Scalar | The minimum value in self |
Examples
nth
Return the n
th value (0-indexed) over a window.
.nth(0)
is equivalent to .first()
. Negative will result in NULL
.
If the value of n
is greater than the number of rows in the window,
NULL
will be returned.
Parameters
Name | Type | Description | Default |
---|---|---|---|
n | int | ir.IntegerValue | Desired rank value | required |
Returns
Name | Type | Description |
---|---|---|
Column | The nth value over a window |
nunique
Compute the number of distinct rows in an expression.
Parameters
Name | Type | Description | Default |
---|---|---|---|
where | ir.BooleanValue | None | Filter expression | None |
Returns
Name | Type | Description |
---|---|---|
IntegerScalar | Number of distinct elements in an expression |