>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values": [-1, 2, -3, 4]})
>>> t.values.abs()
┏━━━━━━━━━━━━━┓ ┃ Abs(values) ┃ ┡━━━━━━━━━━━━━┩ │ int64 │ ├─────────────┤ │ 1 │ │ 2 │ │ 3 │ │ 4 │ └─────────────┘
Integer, floating point, decimal, and boolean expressions.
Name | Description |
---|---|
abs | Return the absolute value of self . |
acos | Compute the arc cosine of self . |
asin | Compute the arc sine of self . |
atan | Compute the arc tangent of self . |
atan2 | Compute the two-argument version of arc tangent. |
ceil | Return the ceiling of self . |
clip | Trim values outside of lower and upper bounds. |
cos | Compute the cosine of self . |
cot | Compute the cotangent of self . |
degrees | Compute the degrees of self radians. |
exp | Compute \(e^\texttt{self}\). |
floor | Return the floor of an expression. |
ln | Compute \(\ln\left(\texttt{self}\right)\). |
log | Compute \(\log_{\texttt{base}}\left(\texttt{self}\right)\). |
log10 | Compute \(\log_{10}\left(\texttt{self}\right)\). |
log2 | Compute \(\log_{2}\left(\texttt{self}\right)\). |
negate | Negate a numeric expression. |
point | Return a point constructed from the coordinate values. |
radians | Compute radians from self degrees. |
round | Round values to an indicated number of decimal places. |
sign | Return the sign of the input. |
sin | Compute the sine of self . |
sqrt | Compute the square root of self . |
tan | Compute the tangent of self . |
Return the absolute value of self
.
Compute the arc cosine of self
.
Compute the arc sine of self
.
Compute the arc tangent of self
.
Compute the two-argument version of arc tangent.
Return the ceiling of self
.
Trim values outside of lower
and upper
bounds.
NULL
values are preserved and are not replaced with bounds.
Name | Type | Description | Default |
---|---|---|---|
lower | NumericValue | None | Lower bound | None |
upper | NumericValue | None | Upper bound | None |
Name | Type | Description |
---|---|---|
NumericValue | Clipped input |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {"values": [None, 2, 3, None, 5, None, None, 8]},
... schema=dict(values="int"),
... )
>>> t.values.clip(lower=3, upper=6)
┏━━━━━━━━━━━━━━━━━━━━┓ ┃ Clip(values, 3, 6) ┃ ┡━━━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├────────────────────┤ │ NULL │ │ 3 │ │ 3 │ │ NULL │ │ 5 │ │ NULL │ │ NULL │ │ 6 │ └────────────────────┘
Compute the cosine of self
.
Compute the cotangent of self
.
Compute the degrees of self
radians.
>>> import ibis
>>> ibis.options.interactive = True
>>> from math import pi
>>> t = ibis.memtable({"values": [0, pi / 2, pi, 3 * pi / 2, 2 * pi]})
>>> t.values.degrees()
┏━━━━━━━━━━━━━━━━━┓ ┃ Degrees(values) ┃ ┡━━━━━━━━━━━━━━━━━┩ │ float64 │ ├─────────────────┤ │ 0.0 │ │ 90.0 │ │ 180.0 │ │ 270.0 │ │ 360.0 │ └─────────────────┘
Compute \(e^\texttt{self}\).
Name | Type | Description |
---|---|---|
NumericValue | \(e^\texttt{self}\) |
Return the floor of an expression.
Compute \(\ln\left(\texttt{self}\right)\).
Compute \(\log_{\texttt{base}}\left(\texttt{self}\right)\).
Name | Type | Description | Default |
---|---|---|---|
base | NumericValue | None | The base of the logarithm. If None , base e is used. |
None |
Name | Type | Description |
---|---|---|
NumericValue | Logarithm of arg with base base |
Compute \(\log_{10}\left(\texttt{self}\right)\).
Compute \(\log_{2}\left(\texttt{self}\right)\).
Negate a numeric expression.
Name | Type | Description |
---|---|---|
NumericValue | A numeric value expression |
Return a point constructed from the coordinate values.
Constant coordinates result in construction of a POINT
literal or column.
Name | Type | Description | Default |
---|---|---|---|
right | int | float | NumericValue | Y coordinate | required |
Name | Type | Description |
---|---|---|
PointValue |
Points |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.zones.fetch()
>>> t.x_cent.point(t.y_cent)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ GeoPoint(x_cent, y_cent) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ point:geometry │ ├──────────────────────────────────┤ │ <POINT (935996.821 191376.75)> │ │ <POINT (1031085.719 164018.754)> │ │ <POINT (1026452.617 254265.479)> │ │ <POINT (990633.981 202959.782)> │ │ <POINT (931871.37 140681.351)> │ │ <POINT (964319.735 157998.936)> │ │ <POINT (1006496.679 216719.218)> │ │ <POINT (1005551.571 222936.088)> │ │ <POINT (1043002.677 212969.849)> │ │ <POINT (1042223.605 186706.496)> │ │ … │ └──────────────────────────────────┘
Compute radians from self
degrees.
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values": [0, 90, 180, 270, 360]})
>>> t.values.radians()
┏━━━━━━━━━━━━━━━━━┓ ┃ Radians(values) ┃ ┡━━━━━━━━━━━━━━━━━┩ │ float64 │ ├─────────────────┤ │ 0.000000 │ │ 1.570796 │ │ 3.141593 │ │ 4.712389 │ │ 6.283185 │ └─────────────────┘
Round values to an indicated number of decimal places.
Name | Type | Description | Default |
---|---|---|---|
digits | int | IntegerValue | The number of digits to round to. Here’s how the digits parameter affects the expression output type: - digits is False -y; self.type() is decimal → decimal - digits is nonzero; self.type() is decimal → decimal - digits is False -y; self.type() is Floating → int64 - digits is nonzero; self.type() is Floating → float64 |
0 |
Name | Type | Description |
---|---|---|
NumericValue | The rounded expression |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values": [1.22, 1.64, 2.15, 2.54]})
>>> t
┏━━━━━━━━━┓ ┃ values ┃ ┡━━━━━━━━━┩ │ float64 │ ├─────────┤ │ 1.22 │ │ 1.64 │ │ 2.15 │ │ 2.54 │ └─────────┘
┏━━━━━━━━━━━━━━━━━━┓ ┃ Round(values, 0) ┃ ┡━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├──────────────────┤ │ 1 │ │ 2 │ │ 2 │ │ 3 │ └──────────────────┘
Return the sign of the input.
Compute the sine of self
.
Compute the square root of self
.
Compute the tangent of self
.
Name | Description |
---|---|
approx_quantile | Compute one or more approximate quantiles of a column. |
bucket | Compute a discrete binning of a numeric array. |
corr | Return the correlation of two numeric columns. |
cov | Return the covariance of two numeric columns. |
cummean | Return the cumulative mean of the input. |
cumsum | Return the cumulative sum of the input. |
histogram | Compute a histogram with fixed width bins. |
mean | Return the mean of a numeric column. |
std | Return the standard deviation of a numeric column. |
sum | Return the sum of a numeric column. |
var | Return the variance of a numeric column. |
Compute one or more approximate quantiles of a column.
Whether the result is an approximation depends on the backend.
Name | Type | Description | Default |
---|---|---|---|
quantile | float | ir .NumericValue | Sequence[ir .NumericValue | float] |
0 <= quantile <= 1 , or an array of such values indicating the quantile or quantiles to compute |
required |
where | ir .BooleanValue | None |
Boolean filter for input values | None |
Name | Type | Description |
---|---|---|
Scalar | Quantile of the input |
Compute the approximate 0.50 quantile of bill_depth_mm
.
Compute multiple approximate quantiles in one call - in this case the result is an array.
Compute a discrete binning of a numeric array.
Name | Type | Description | Default |
---|---|---|---|
buckets | Sequence[int] | List of buckets | required |
closed | Literal['left', 'right'] | Which side of each interval is closed. For example: python buckets = [0, 100, 200] closed = "left" # 100 falls in 2nd bucket closed = "right" # 100 falls in 1st bucket |
'left' |
close_extreme | bool | Whether the extreme values fall in the last bucket | True |
include_over | bool | Include values greater than the last bucket in the last bucket | False |
include_under | bool | Include values less than the first bucket in the first bucket | False |
Name | Type | Description |
---|---|---|
IntegerColumn | A categorical column expression |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "values": [-1, 3, 5, 6, 8, 10, 11],
... }
... )
>>> buckets = [0, 5, 10]
>>> t.mutate(
... bucket_closed_left=t.values.bucket(buckets),
... bucket_closed_right=t.values.bucket(buckets, closed="right"),
... bucket_over_under=t.values.bucket(buckets, include_over=True, include_under=True),
... )
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ ┃ values ┃ bucket_closed_left ┃ bucket_closed_right ┃ bucket_over_under ┃ ┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩ │ int64 │ int8 │ int8 │ int8 │ ├────────┼────────────────────┼─────────────────────┼───────────────────┤ │ -1 │ NULL │ NULL │ 0 │ │ 3 │ 0 │ 0 │ 1 │ │ 5 │ 1 │ 0 │ 2 │ │ 6 │ 1 │ 1 │ 2 │ │ 8 │ 1 │ 1 │ 2 │ │ 10 │ 1 │ 1 │ 2 │ │ 11 │ NULL │ NULL │ 3 │ └────────┴────────────────────┴─────────────────────┴───────────────────┘
Return the correlation of two numeric columns.
Name | Type | Description | Default |
---|---|---|---|
right | NumericColumn | Numeric column | required |
where | ir .BooleanValue | None |
Filter | None |
how | Literal['sample', 'pop'] | Population or sample correlation | 'sample' |
Name | Type | Description |
---|---|---|
NumericScalar |
The correlation of left and right |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "left": [1, 3, 3, 4, 5, 7],
... "right": [7, 5, 4, 3, 3, 1],
... }
... )
>>> t.left.corr(t.right, how="pop")
┌────────┐
│ -0.968 │
└────────┘
┏━━━━━━━┳━━━━━━━┳━━━━━━━━━━┓ ┃ left ┃ right ┃ corr_col ┃ ┡━━━━━━━╇━━━━━━━╇━━━━━━━━━━┩ │ int64 │ int64 │ float64 │ ├───────┼───────┼──────────┤ │ 1 │ 7 │ -0.968 │ │ 3 │ 5 │ -0.968 │ │ 3 │ 4 │ -0.968 │ │ 4 │ 3 │ -0.968 │ │ 5 │ 3 │ -0.968 │ │ 7 │ 1 │ -0.968 │ └───────┴───────┴──────────┘
Return the covariance of two numeric columns.
Name | Type | Description | Default |
---|---|---|---|
right | NumericColumn | Numeric column | required |
where | ir .BooleanValue | None |
Filter | None |
how | Literal['sample', 'pop'] | Population or sample covariance | 'sample' |
Name | Type | Description |
---|---|---|
NumericScalar |
The covariance of self and right |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "left": [1, 3, 3, 4, 5, 7],
... "right": [7, 5, 4, 3, 3, 1],
... }
... )
>>> t.left.cov(t.right)
┌───────────┐
│ -4.033333 │
└───────────┘
┏━━━━━━━┳━━━━━━━┳━━━━━━━━━━━┓ ┃ left ┃ right ┃ cov_col ┃ ┡━━━━━━━╇━━━━━━━╇━━━━━━━━━━━┩ │ int64 │ int64 │ float64 │ ├───────┼───────┼───────────┤ │ 1 │ 7 │ -3.361111 │ │ 3 │ 5 │ -3.361111 │ │ 3 │ 4 │ -3.361111 │ │ 4 │ 3 │ -3.361111 │ │ 5 │ 3 │ -3.361111 │ │ 7 │ 1 │ -3.361111 │ └───────┴───────┴───────────┘
Return the cumulative mean of the input.
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "id": [1, 2, 3, 4, 5, 6],
... "grouper": ["a", "a", "a", "b", "b", "c"],
... "values": [3, 2, 1, 2, 3, 2],
... }
... )
>>> t.mutate(cummean=t.values.cummean()).order_by("id")
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ cummean ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━┩ │ int64 │ string │ int64 │ float64 │ ├───────┼─────────┼────────┼──────────┤ │ 1 │ a │ 3 │ 3.000000 │ │ 2 │ a │ 2 │ 2.500000 │ │ 3 │ a │ 1 │ 2.000000 │ │ 4 │ b │ 2 │ 2.000000 │ │ 5 │ b │ 3 │ 2.200000 │ │ 6 │ c │ 2 │ 2.166667 │ └───────┴─────────┴────────┴──────────┘
>>> t.mutate(cummean=t.values.cummean(where=t.grouper != "c", group_by="grouper")).order_by(
... "id"
... )
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ cummean ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━┩ │ int64 │ string │ int64 │ float64 │ ├───────┼─────────┼────────┼─────────┤ │ 1 │ a │ 3 │ 3.0 │ │ 2 │ a │ 2 │ 2.5 │ │ 3 │ a │ 1 │ 2.0 │ │ 4 │ b │ 2 │ 2.0 │ │ 5 │ b │ 3 │ 2.5 │ │ 6 │ c │ 2 │ NULL │ └───────┴─────────┴────────┴─────────┘
Return the cumulative sum of the input.
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "id": [1, 2, 3, 4, 5, 6],
... "grouper": ["a", "a", "a", "b", "b", "c"],
... "values": [3, 2, 1, 2, 3, 2],
... }
... )
>>> t.mutate(cumsum=t.values.cumsum())
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ cumsum ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━┩ │ int64 │ string │ int64 │ int64 │ ├───────┼─────────┼────────┼────────┤ │ 1 │ a │ 3 │ 3 │ │ 2 │ a │ 2 │ 5 │ │ 3 │ a │ 1 │ 6 │ │ 4 │ b │ 2 │ 8 │ │ 5 │ b │ 3 │ 11 │ │ 6 │ c │ 2 │ 13 │ └───────┴─────────┴────────┴────────┘
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ cumsum ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━┩ │ int64 │ string │ int64 │ int64 │ ├───────┼─────────┼────────┼────────┤ │ 1 │ a │ 3 │ 3 │ │ 2 │ a │ 2 │ 5 │ │ 3 │ a │ 1 │ 6 │ │ 4 │ b │ 2 │ 8 │ │ 5 │ b │ 3 │ 11 │ │ 6 │ c │ 2 │ 11 │ └───────┴─────────┴────────┴────────┘
Compute a histogram with fixed width bins.
Name | Type | Description | Default |
---|---|---|---|
nbins | int | None | If supplied, will be used to compute the binwidth | None |
binwidth | float | None | If not supplied, computed from the data (actual max and min values) | None |
base | float | None | The value of the first histogram bin. Defaults to the minimum value of column . |
None |
eps | float | Allowed floating point epsilon for histogram base | 1e-13 |
Name | Type | Description |
---|---|---|
Column | Bucketed column |
Compute a histogram with 5 bins.
┏━━━━━━━━┳━━━━━━━━━━━┓ ┃ values ┃ histogram ┃ ┡━━━━━━━━╇━━━━━━━━━━━┩ │ int64 │ int64 │ ├────────┼───────────┤ │ -1 │ 0 │ │ 3 │ 0 │ │ 5 │ 1 │ │ 6 │ 1 │ │ 8 │ 1 │ │ 10 │ 2 │ │ 11 │ 2 │ │ 23 │ 4 │ │ 25 │ 4 │ └────────┴───────────┘
Compute a histogram with a fixed bin width of 10.
Return the mean of a numeric column.
Name | Type | Description | Default |
---|---|---|---|
where | ir .BooleanValue | None |
Filter | None |
Name | Type | Description |
---|---|---|
NumericScalar |
The mean of the input expression |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "id": [1, 2, 3, 4, 5, 6],
... "grouper": ["a", "a", "a", "b", "b", "c"],
... "values": [3, 2, 1, 2, 3, 2],
... }
... )
>>> t.mutate(mean_col=t.values.mean())
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ mean_col ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━┩ │ int64 │ string │ int64 │ float64 │ ├───────┼─────────┼────────┼──────────┤ │ 1 │ a │ 3 │ 2.166667 │ │ 2 │ a │ 2 │ 2.166667 │ │ 3 │ a │ 1 │ 2.166667 │ │ 4 │ b │ 2 │ 2.166667 │ │ 5 │ b │ 3 │ 2.166667 │ │ 6 │ c │ 2 │ 2.166667 │ └───────┴─────────┴────────┴──────────┘
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ mean_col ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━┩ │ int64 │ string │ int64 │ float64 │ ├───────┼─────────┼────────┼──────────┤ │ 1 │ a │ 3 │ 2.2 │ │ 2 │ a │ 2 │ 2.2 │ │ 3 │ a │ 1 │ 2.2 │ │ 4 │ b │ 2 │ 2.2 │ │ 5 │ b │ 3 │ 2.2 │ │ 6 │ c │ 2 │ 2.2 │ └───────┴─────────┴────────┴──────────┘
Return the standard deviation of a numeric column.
Name | Type | Description | Default |
---|---|---|---|
where | ir .BooleanValue | None |
Filter | None |
how | Literal['sample', 'pop'] | Sample or population standard deviation | 'sample' |
Name | Type | Description |
---|---|---|
NumericScalar |
Standard deviation of arg |
Return the sum of a numeric column.
Name | Type | Description | Default |
---|---|---|---|
where | ir .BooleanValue | None |
Filter | None |
Name | Type | Description |
---|---|---|
NumericScalar |
The sum of the input expression |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "id": [1, 2, 3, 4, 5, 6],
... "grouper": ["a", "a", "a", "b", "b", "c"],
... "values": [3, 2, 1, 2, 3, 2],
... }
... )
>>> t.mutate(sum_col=t.values.sum())
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ sum_col ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━┩ │ int64 │ string │ int64 │ int64 │ ├───────┼─────────┼────────┼─────────┤ │ 1 │ a │ 3 │ 13 │ │ 2 │ a │ 2 │ 13 │ │ 3 │ a │ 1 │ 13 │ │ 4 │ b │ 2 │ 13 │ │ 5 │ b │ 3 │ 13 │ │ 6 │ c │ 2 │ 13 │ └───────┴─────────┴────────┴─────────┘
┏━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┓ ┃ id ┃ grouper ┃ values ┃ sum_col ┃ ┡━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━┩ │ int64 │ string │ int64 │ int64 │ ├───────┼─────────┼────────┼─────────┤ │ 1 │ a │ 3 │ 11 │ │ 2 │ a │ 2 │ 11 │ │ 3 │ a │ 1 │ 11 │ │ 4 │ b │ 2 │ 11 │ │ 5 │ b │ 3 │ 11 │ │ 6 │ c │ 2 │ 11 │ └───────┴─────────┴────────┴─────────┘
Return the variance of a numeric column.
Name | Type | Description | Default |
---|---|---|---|
where | ir .BooleanValue | None |
Filter | None |
how | Literal['sample', 'pop'] | Sample or population variance | 'sample' |
Name | Type | Description |
---|---|---|
NumericScalar |
Standard deviation of arg |
Name | Description |
---|---|
as_interval | Convert an integer to an interval. |
as_timestamp | Convert an integral UNIX timestamp to a timestamp expression. |
convert_base | Convert an integer from one base to another. |
label | Label a set of integer values with strings. |
Convert an integer to an interval.
Name | Type | Description | Default |
---|---|---|---|
unit | Literal['Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns'] | Unit for the resulting interval | 's' |
Name | Type | Description |
---|---|---|
IntervalValue |
An interval in units of unit |
>>> from datetime import datetime
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "timestamp_col": [
... datetime(2024, 1, 1, 0, 0, 0),
... datetime(2024, 1, 1, 0, 0, 0),
... datetime(2024, 1, 1, 0, 0, 0),
... ],
... "int_col": [1, 2, 3],
... }
... )
>>> t.int_col.as_interval("h")
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ IntervalFromInteger(int_col, HOUR) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ interval('h') │ ├────────────────────────────────────────────────────────────┤ │ MonthDayNano(months=0, days=0, nanoseconds=3600000000000) │ │ MonthDayNano(months=0, days=0, nanoseconds=7200000000000) │ │ MonthDayNano(months=0, days=0, nanoseconds=10800000000000) │ └────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓ ┃ timestamp_col ┃ int_col ┃ timestamp_added_col ┃ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩ │ timestamp │ int64 │ timestamp │ ├─────────────────────┼─────────┼─────────────────────┤ │ 2024-01-01 00:00:00 │ 1 │ 2024-01-01 01:00:00 │ │ 2024-01-01 00:00:00 │ 2 │ 2024-01-01 02:00:00 │ │ 2024-01-01 00:00:00 │ 3 │ 2024-01-01 03:00:00 │ └─────────────────────┴─────────┴─────────────────────┘
Convert an integral UNIX timestamp to a timestamp expression.
Name | Type | Description | Default |
---|---|---|---|
unit | Literal['s', 'ms', 'us'] | The resolution of arg |
required |
Name | Type | Description |
---|---|---|
TimestampValue |
self converted to a timestamp |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "int_col": [0, 1730501716, 2147483647],
... }
... )
>>> t.int_col.as_timestamp("s")
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ TimestampFromUNIX(int_col, SECOND) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ timestamp │ ├────────────────────────────────────┤ │ 1970-01-01 00:00:00 │ │ 2024-11-01 22:55:16 │ │ 2038-01-19 03:14:07 │ └────────────────────────────────────┘
Convert an integer from one base to another.
Name | Type | Description | Default |
---|---|---|---|
from_base | IntegerValue | Numeric base of expression | required |
to_base | IntegerValue | New base | required |
Name | Type | Description |
---|---|---|
IntegerValue | Converted expression |
Label a set of integer values with strings.
Name | Type | Description | Default |
---|---|---|---|
labels | Iterable[str] | An iterable of string labels. Each integer value in self will be mapped to a value in labels . |
required |
nulls | str | None | String label to use for NULL values |
None |
Name | Type | Description |
---|---|---|
StringValue |
self labeled with labels |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [0, 1, 0, 2]})
>>> t.select(t.a, labeled=t.a.label(["a", "b", "c"]))
┏━━━━━━━┳━━━━━━━━━┓ ┃ a ┃ labeled ┃ ┡━━━━━━━╇━━━━━━━━━┩ │ int64 │ string │ ├───────┼─────────┤ │ 0 │ a │ │ 1 │ b │ │ 0 │ a │ │ 2 │ c │ └───────┴─────────┘
Name | Description |
---|---|
bit_and | Aggregate the column using the bitwise and operator. |
bit_or | Aggregate the column using the bitwise or operator. |
bit_xor | Aggregate the column using the bitwise exclusive or operator. |
Aggregate the column using the bitwise and operator.
Aggregate the column using the bitwise or operator.
Aggregate the column using the bitwise exclusive or operator.
Name | Description |
---|---|
isinf | Return whether the value is infinity. |
isnan | Return whether the value is NaN. |
Return whether the value is infinity.
Return whether the value is NaN.
Name | Description |
---|---|
ifelse | Construct a ternary conditional expression. |
negate | DEPRECATED. |
Construct a ternary conditional expression.
Name | Type | Description | Default |
---|---|---|---|
true_expr | ir .Value |
Expression to return if self evaluates to True |
required |
false_expr | ir .Value |
Expression to return if self evaluates to False or NULL |
required |
Name | Type | Description |
---|---|---|
Value |
The value of true_expr if arg is True else false_expr |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"is_person": [True, False, True, None]})
>>> t.is_person.ifelse("yes", "no")
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ IfElse(is_person, 'yes', 'no') ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ ├────────────────────────────────┤ │ yes │ │ no │ │ yes │ │ no │ └────────────────────────────────┘
DEPRECATED.
Name | Description |
---|---|
all | Return whether all elements are True . |
any | Return whether at least one element is True . |
cumall | Accumulate the all aggregate. |
cumany | Accumulate the any aggregate. |
notall | Return whether not all elements are True . |
notany | Return whether no elements are True . |
Return whether all elements are True
.
Name | Type | Description | Default |
---|---|---|---|
where | BooleanValue | None | Optional filter for the aggregation | None |
Name | Type | Description |
---|---|---|
BooleanValue | Whether all elements are True |
Return whether at least one element is True
.
If the expression does not reference any foreign tables, the result will be a scalar reduction, otherwise it will be a deferred expression constructing an exists subquery when passed to a table method.
Name | Type | Description | Default |
---|---|---|---|
where | BooleanValue | None | Optional filter for the aggregation | None |
Name | Type | Description |
---|---|---|
BooleanValue | Whether at least one element is True . |
Consider the following ibis expressions
import ibis
t = ibis.table(dict(a="string"))
s = ibis.table(dict(a="string"))
cond = (t.a == s.a).any()
Without knowing the table to use as the outer query there are two ways to turn this expression into a SQL EXISTS
predicate, depending on which of t
or s
is filtered on.
Filtering from t
:
Filtering from s
:
Notably the correlated subquery cannot stand on its own.
Accumulate the all
aggregate.
Name | Type | Description |
---|---|---|
BooleanColumn | A boolean column with the cumulative all aggregate. |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr": [1, 2, 3, 4]})
>>> ((t.arr > 1) & (t.arr >= 1)).cumall()
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ All(And(Greater(arr, 1), GreaterEqual(arr, 1))) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ boolean │ ├─────────────────────────────────────────────────┤ │ False │ │ False │ │ False │ │ False │ └─────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ All(And(Greater(arr, 0), GreaterEqual(arr, 1))) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ boolean │ ├─────────────────────────────────────────────────┤ │ True │ │ True │ │ True │ │ True │ └─────────────────────────────────────────────────┘
Accumulate the any
aggregate.
Name | Type | Description |
---|---|---|
BooleanColumn | A boolean column with the cumulative any aggregate. |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr": [1, 2, 3, 4]})
>>> ((t.arr > 1) | (t.arr >= 1)).cumany()
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Any(Or(Greater(arr, 1), GreaterEqual(arr, 1))) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ boolean │ ├────────────────────────────────────────────────┤ │ True │ │ True │ │ True │ │ True │ └────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Any(And(Greater(arr, 1), GreaterEqual(arr, 1))) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ boolean │ ├─────────────────────────────────────────────────┤ │ False │ │ True │ │ True │ │ True │ └─────────────────────────────────────────────────┘
Return whether not all elements are True
.
Name | Type | Description | Default |
---|---|---|---|
where | BooleanValue | None | Optional filter for the aggregation | None |
Name | Type | Description |
---|---|---|
BooleanValue | Whether not all elements are True |
Return whether no elements are True
.
Name | Type | Description | Default |
---|---|---|---|
where | BooleanValue | None | Optional filter for the aggregation | None |
Name | Type | Description |
---|---|---|
BooleanValue | Whether no elements are True . |
Combine multiple predicates using &
.
Name | Type | Description | Default |
---|---|---|---|
predicates | ir .BooleanValue |
Boolean value expressions | () |
Name | Type | Description |
---|---|---|
BooleanValue |
A new predicate that evaluates to True if all composing predicates are True. If no predicates were provided, returns True. |
Combine multiple predicates using |
.
Name | Type | Description | Default |
---|---|---|---|
predicates | ir .BooleanValue |
Boolean value expressions | () |
Name | Type | Description |
---|---|---|
BooleanValue |
A new predicate that evaluates to True if any composing predicates are True. If no predicates were provided, returns False. |
Return a random floating point number in the range [0.0, 1.0).
Similar to random.random
in the Python standard library.
random
ibis.random()
will generate a column of distinct random numbers even if the same instance of ibis.random()
is re-used.
When Ibis compiles an expression to SQL, each place where random
is used will render as a separate call to the given backend’s random number generator.
>>> from ibis.interactive import *
>>> t = ibis.memtable({"a": range(5)})
>>> r_a = ibis.random()
>>> t.mutate(random_1=r_a, random_2=r_a) # doctest: +SKIP
┏━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┓
┃ a ┃ random_1 ┃ random_2 ┃
┡━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━┩
│ int64 │ float64 │ float64 │
├───────┼──────────┼──────────┤
│ 0 │ 0.191130 │ 0.098715 │
│ 1 │ 0.255262 │ 0.828454 │
│ 2 │ 0.011804 │ 0.392275 │
│ 3 │ 0.309941 │ 0.347300 │
│ 4 │ 0.482783 │ 0.095562 │
└───────┴──────────┴──────────┘
Name | Type | Description |
---|---|---|
FloatingScalar |
Random float value expression |
e
pi