Integer, floating point, decimal, and boolean expressions.
NumericValue
Methods
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
.
abs
Return the absolute value of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 2 , - 3 , 4 ]})
>>> t.values.abs ()
βββββββββββββββ
β Abs(values) β
β‘ββββββββββββββ©
β int64 β
βββββββββββββββ€
β 1 β
β 2 β
β 3 β
β 4 β
βββββββββββββββ
acos
Compute the arc cosine of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.acos()
ββββββββββββββββ
β Acos(values) β
β‘βββββββββββββββ©
β float64 β
ββββββββββββββββ€
β 3.141593 β
β 1.570796 β
β 0.000000 β
ββββββββββββββββ
asin
Compute the arc sine of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.asin()
ββββββββββββββββ
β Asin(values) β
β‘βββββββββββββββ©
β float64 β
ββββββββββββββββ€
β -1.570796 β
β 0.000000 β
β 1.570796 β
ββββββββββββββββ
atan
Compute the arc tangent of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.atan()
ββββββββββββββββ
β Atan(values) β
β‘βββββββββββββββ©
β float64 β
ββββββββββββββββ€
β -0.785398 β
β 0.000000 β
β 0.785398 β
ββββββββββββββββ
atan2
Compute the two-argument version of arc tangent.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.atan2(0 )
ββββββββββββββββββββ
β Atan2(values, 0) β
β‘βββββββββββββββββββ©
β float64 β
ββββββββββββββββββββ€
β -1.570796 β
β 0.000000 β
β 1.570796 β
ββββββββββββββββββββ
ceil
Return the ceiling of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [1 , 1.1 , 2 , 2.1 , 3.3 ]})
>>> t.values.ceil()
ββββββββββββββββ
β Ceil(values) β
β‘βββββββββββββββ©
β int64 β
ββββββββββββββββ€
β 1 β
β 2 β
β 2 β
β 3 β
β 4 β
ββββββββββββββββ
clip
clip(lower= None , upper= None )
Trim values outside of lower
and upper
bounds.
NULL
values are preserved and are not replaced with bounds.
Examples
>>> 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 β
ββββββββββββββββββββββ
cos
Compute the cosine of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.cos()
βββββββββββββββ
β Cos(values) β
β‘ββββββββββββββ©
β float64 β
βββββββββββββββ€
β 0.540302 β
β 1.000000 β
β 0.540302 β
βββββββββββββββ
cot
Compute the cotangent of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , - 2 , 3 ]})
>>> t.values.cot()
βββββββββββββββ
β Cot(values) β
β‘ββββββββββββββ©
β float64 β
βββββββββββββββ€
β -0.642093 β
β 0.457658 β
β -7.015253 β
βββββββββββββββ
degrees
Compute the degrees of self
radians.
Examples
>>> 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 β
βββββββββββββββββββ
exp
Compute \(e^\texttt{self}\) .
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : range (4 )})
>>> t.values.exp()
βββββββββββββββ
β Exp(values) β
β‘ββββββββββββββ©
β float64 β
βββββββββββββββ€
β 1.000000 β
β 2.718282 β
β 7.389056 β
β 20.085537 β
βββββββββββββββ
floor
Return the floor of an expression.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [1 , 1.1 , 2 , 2.1 , 3.3 ]})
>>> t.values.floor()
βββββββββββββββββ
β Floor(values) β
β‘ββββββββββββββββ©
β int64 β
βββββββββββββββββ€
β 1 β
β 1 β
β 2 β
β 2 β
β 3 β
βββββββββββββββββ
ln
Compute \(\ln\left(\texttt{self}\right)\) .
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [1 , 2.718281828 , 3 ]})
>>> t.values.ln()
ββββββββββββββ
β Ln(values) β
β‘βββββββββββββ©
β float64 β
ββββββββββββββ€
β 0.000000 β
β 1.000000 β
β 1.098612 β
ββββββββββββββ
log
Compute \(\log_{\texttt{base}}\left(\texttt{self}\right)\) .
Parameters
base
NumericValue | None
The base of the logarithm. If None
, base e
is used.
None
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> from math import e
>>> t = ibis.memtable({"values" : [e, e** 2 , e** 3 ]})
>>> t.values.log()
βββββββββββββββ
β Log(values) β
β‘ββββββββββββββ©
β float64 β
βββββββββββββββ€
β 1.0 β
β 2.0 β
β 3.0 β
βββββββββββββββ
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [10 , 100 , 1000 ]})
>>> t.values.log(10 )
βββββββββββββββββββ
β Log(values, 10) β
β‘ββββββββββββββββββ©
β float64 β
βββββββββββββββββββ€
β 1.0 β
β 2.0 β
β 3.0 β
βββββββββββββββββββ
log10
Compute \(\log_{10}\left(\texttt{self}\right)\) .
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [1 , 10 , 100 ]})
>>> t.values.log10()
βββββββββββββββββ
β Log10(values) β
β‘ββββββββββββββββ©
β float64 β
βββββββββββββββββ€
β 0.0 β
β 1.0 β
β 2.0 β
βββββββββββββββββ
log2
Compute \(\log_{2}\left(\texttt{self}\right)\) .
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [1 , 2 , 4 , 8 ]})
>>> t.values.log2()
ββββββββββββββββ
β Log2(values) β
β‘βββββββββββββββ©
β float64 β
ββββββββββββββββ€
β 0.0 β
β 1.0 β
β 2.0 β
β 3.0 β
ββββββββββββββββ
negate
Negate a numeric expression.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.negate()
ββββββββββββββββββ
β Negate(values) β
β‘βββββββββββββββββ©
β int64 β
ββββββββββββββββββ€
β 1 β
β 0 β
β -1 β
ββββββββββββββββββ
point
Return a point constructed from the coordinate values.
Constant coordinates result in construction of a POINT
literal or column.
Examples
>>> 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 ) > β
β β¦ β
ββββββββββββββββββββββββββββββββββββ
radians
Compute radians from self
degrees.
Examples
>>> 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
Round values to an indicated number of decimal places.
Parameters
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
Examples
>>> 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 β
ββββββββββββββββββββ
ββββββββββββββββββββ
β Round(values, 1) β
β‘βββββββββββββββββββ©
β float64 β
ββββββββββββββββββββ€
β 1.2 β
β 1.6 β
β 2.2 β
β 2.5 β
ββββββββββββββββββββ
sign
Return the sign of the input.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 2 , - 3 , 4 ]})
>>> t.values.sign()
ββββββββββββββββ
β Sign(values) β
β‘βββββββββββββββ©
β int64 β
ββββββββββββββββ€
β -1 β
β 1 β
β -1 β
β 1 β
ββββββββββββββββ
sin
Compute the sine of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.sin()
βββββββββββββββ
β Sin(values) β
β‘ββββββββββββββ©
β float64 β
βββββββββββββββ€
β -0.841471 β
β 0.000000 β
β 0.841471 β
βββββββββββββββ
sqrt
Compute the square root of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [1 , 4 , 9 , 16 ]})
>>> t.values.sqrt()
ββββββββββββββββ
β Sqrt(values) β
β‘βββββββββββββββ©
β float64 β
ββββββββββββββββ€
β 1.0 β
β 2.0 β
β 3.0 β
β 4.0 β
ββββββββββββββββ
tan
Compute the tangent of self
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values" : [- 1 , 0 , 1 ]})
>>> t.values.tan()
βββββββββββββββ
β Tan(values) β
β‘ββββββββββββββ©
β float64 β
βββββββββββββββ€
β -1.557408 β
β 0.000000 β
β 1.557408 β
βββββββββββββββ
NumericColumn
Methods
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.
kurtosis
Return the kurtosis of a numeric column.
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.
approx_quantile
approx_quantile(quantile, / , * , where= None )
Compute one or more approximate quantiles of a column.
Whether the result is an approximation depends on the backend.
Parameters
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
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
Compute the approximate 0.50 quantile of bill_depth_mm
.
>>> t.bill_depth_mm.approx_quantile(0.50 )
ββββββββββ
β 17.318 β
ββββββββββ
Compute multiple approximate quantiles in one call - in this case the result is an array.
>>> t.bill_depth_mm.approx_quantile([0.25 , 0.75 ])
ββββββββββββββββββββββββββ
β [ 15.565625 , 18.671875 ] β
ββββββββββββββββββββββββββ
bucket
bucket(
buckets,
/ ,
* ,
closed= 'left' ,
close_extreme= True ,
include_under= False ,
include_over= False ,
)
Compute a discrete binning of a numeric array.
Parameters
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
Examples
>>> 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 β
ββββββββββ΄βββββββββββββββββββββ΄ββββββββββββββββββββββ΄ββββββββββββββββββββ
corr
corr(right, / , * , where= None , how= 'sample' )
Return the correlation of two numeric columns.
Parameters
right
NumericColumn
Numeric column
required
where
ir
.BooleanValue
| None
Filter
None
how
Literal ['sample', 'pop']
Population or sample correlation
'sample'
Returns
NumericScalar
The correlation of left
and right
Examples
>>> 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 β
ββββββββββ
>>> t.mutate(corr_col= t.left.corr(t.right, how= "pop" ))
βββββββββ³ββββββββ³βββββββββββ
β 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 β
βββββββββ΄ββββββββ΄βββββββββββ
cov
cov(right, / , * , where= None , how= 'sample' )
Return the covariance of two numeric columns.
Parameters
right
NumericColumn
Numeric column
required
where
ir
.BooleanValue
| None
Filter
None
how
Literal ['sample', 'pop']
Population or sample covariance
'sample'
Returns
NumericScalar
The covariance of self
and right
Examples
>>> 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 β
βββββββββββββ
>>> t.left.cov(t.right, how= "pop" )
βββββββββββββ
β -3.361111 β
βββββββββββββ
>>> t.mutate(cov_col= t.left.cov(t.right, how= "pop" ))
βββββββββ³ββββββββ³ββββββββββββ
β 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 β
βββββββββ΄ββββββββ΄ββββββββββββ
cummean
cummean(where= None , group_by= None , order_by= None )
Return the cumulative mean of the input.
Examples
>>> 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄ββββββββββ
cumsum
cumsum(where= None , group_by= None , order_by= None )
Return the cumulative sum of the input.
Examples
>>> 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄βββββββββ
>>> t.mutate(cumsum= t.values.cumsum(where= t.grouper != "c" ))
βββββββββ³ββββββββββ³βββββββββ³βββββββββ
β 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄βββββββββ
histogram
histogram(nbins= None , binwidth= None , base= None , eps= 1e-13 )
Compute a histogram with fixed width bins.
Parameters
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
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "values" : [- 1 , 3 , 5 , 6 , 8 , 10 , 11 , 23 , 25 ],
... }
... )
Compute a histogram with 5 bins.
>>> t.mutate(histogram= t.values.histogram(nbins= 5 ))
ββββββββββ³ββββββββββββ
β 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.
>>> t.mutate(histogram= t.values.histogram(binwidth= 10 ))
ββββββββββ³ββββββββββββ
β values β histogram β
β‘βββββββββββββββββββββ©
β int64 β int64 β
ββββββββββΌββββββββββββ€
β -1 β 0 β
β 3 β 0 β
β 5 β 0 β
β 6 β 0 β
β 8 β 0 β
β 10 β 1 β
β 11 β 1 β
β 23 β 2 β
β 25 β 2 β
ββββββββββ΄ββββββββββββ
kurtosis
kurtosis(where= None , how= 'sample' )
Return the kurtosis of a numeric column.
Parameters
where
ir
.BooleanValue
| None
Filter
None
how
Literal ['sample', 'pop']
Whether to include bias correction. "sample"
includes the correction while "pop"
does not.
'sample'
Returns
NumericScalar
Kurtosis of arg
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "keys" : ["a" , "a" , "b" , "b" , "a" , "a" , "b" , "b" ],
... "values" : [1 , 2 , 3 , 3 , 6 , 4 , 5 , 7 ],
... }
... )
>>> t.values.kurtosis()
ββββββββββββ
β -0.88595 β
ββββββββββββ
>>> t.group_by("keys" ).agg(kurt= t.values.kurtosis()).order_by("keys" )
ββββββββββ³ββββββββββββ
β keys β kurt β
β‘βββββββββββββββββββββ©
β string β float64 β
ββββββββββΌββββββββββββ€
β a β -1.699512 β
β b β -1.289256 β
ββββββββββ΄ββββββββββββ
mean
Return the mean of a numeric column.
Parameters
where
ir
.BooleanValue
| None
Filter
None
Returns
NumericScalar
The mean of the input expression
Examples
>>> 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄βββββββββββ
>>> t.mutate(mean_col= t.values.mean(where= t.grouper != "c" ))
βββββββββ³ββββββββββ³βββββββββ³βββββββββββ
β 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄βββββββββββ
std
std(where= None , how= 'sample' )
Return the standard deviation of a numeric column.
Parameters
where
ir
.BooleanValue
| None
Filter
None
how
Literal ['sample', 'pop']
Sample or population standard deviation
'sample'
Returns
NumericScalar
Standard deviation of arg
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "values" : [1 , 3 , 3 , 4 , 5 , 7 ],
... }
... )
>>> t.values.std()
ββββββββββββ
β 2.041241 β
ββββββββββββ
>>> t.mutate(std_col= t.values.std())
ββββββββββ³βββββββββββ
β values β std_col β
β‘ββββββββββββββββββββ©
β int64 β float64 β
ββββββββββΌβββββββββββ€
β 1 β 2.041241 β
β 3 β 2.041241 β
β 3 β 2.041241 β
β 4 β 2.041241 β
β 5 β 2.041241 β
β 7 β 2.041241 β
ββββββββββ΄βββββββββββ
sum
Return the sum of a numeric column.
Parameters
where
ir
.BooleanValue
| None
Filter
None
Returns
NumericScalar
The sum of the input expression
Examples
>>> 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄ββββββββββ
>>> t.mutate(sum_col= t.values.sum (where= t.grouper != "c" ))
βββββββββ³ββββββββββ³βββββββββ³ββββββββββ
β 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 β
βββββββββ΄ββββββββββ΄βββββββββ΄ββββββββββ
var
var(where= None , how= 'sample' )
Return the variance of a numeric column.
Parameters
where
ir
.BooleanValue
| None
Filter
None
how
Literal ['sample', 'pop']
Sample or population variance
'sample'
Returns
NumericScalar
Standard deviation of arg
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "values" : [1 , 3 , 3 , 4 , 5 , 7 ],
... }
... )
>>> t.values.var()
ββββββββββββ
β 4.166667 β
ββββββββββββ
>>> t.mutate(var_col= t.values.var())
ββββββββββ³βββββββββββ
β values β var_col β
β‘ββββββββββββββββββββ©
β int64 β float64 β
ββββββββββΌβββββββββββ€
β 1 β 4.166667 β
β 3 β 4.166667 β
β 3 β 4.166667 β
β 4 β 4.166667 β
β 5 β 4.166667 β
β 7 β 4.166667 β
ββββββββββ΄βββββββββββ
IntegerValue
Methods
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.
as_interval
Convert an integer to an interval.
Parameters
unit
Literal ['Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns']
Unit for the resulting interval
's'
Examples
>>> 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) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
>>> t.mutate(timestamp_added_col= t.timestamp_col + t.int_col.as_interval("h" ))
βββββββββββββββββββββββ³ββββββββββ³ββββββββββββββββββββββ
β 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 β
βββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββββββ
as_timestamp
Convert an integral UNIX timestamp to a timestamp expression.
Parameters
unit
Literal ['s', 'ms', 'us']
The resolution of arg
required
Examples
>>> 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_base
convert_base(from_base, to_base)
Convert an integer from one base to another.
IntegerColumn
Methods
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.
bit_and
Aggregate the column using the bitwise and operator.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"x" : [- 1 , 0 , 1 ]})
>>> t.x.bit_and()
βββββ
β 0 β
βββββ
>>> t.x.bit_and(where= t.x != 0 )
βββββ
β 1 β
βββββ
bit_or
Aggregate the column using the bitwise or operator.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"x" : [- 1 , 0 , 1 ]})
>>> t.x.bit_or()
ββββββ
β -1 β
ββββββ
>>> t.x.bit_or(where= t.x >= 0 )
βββββ
β 1 β
βββββ
bit_xor
Aggregate the column using the bitwise exclusive or operator.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"x" : [- 1 , 0 , 1 ]})
>>> t.x.bit_xor()
ββββββ
β -2 β
ββββββ
>>> t.x.bit_xor(where= t.x >= 0 )
βββββ
β 1 β
βββββ
FloatingValue
Methods
isinf
Return whether the value is +/-inf. Does NOT detect NULL
and inf
values.
isnan
Return whether the value is NaN. Does NOT detect NULL
and inf
values.
isinf
Return whether the value is +/-inf. Does NOT detect NULL
and inf
values.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"f" : [None , "-inf" , "3.0" , "inf" , "nan" ]})
>>> t = t.mutate(f= ibis._.f.cast(float ))
>>> t.mutate(
... isnull= t.f.isnull(),
... isnan= t.f.isnan(),
... isinf= t.f.isinf(),
... )
βββββββββββ³ββββββββββ³ββββββββββ³ββββββββββ
β f β isnull β isnan β isinf β
β‘ββββββββββββββββββββββββββββββββββββββββ©
β float64 β boolean β boolean β boolean β
βββββββββββΌββββββββββΌββββββββββΌββββββββββ€
β NULL β True β NULL β NULL β
β -inf β False β False β True β
β 3.0 β False β False β False β
β inf β False β False β True β
β nan β False β True β False β
βββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ
isnan
Return whether the value is NaN. Does NOT detect NULL
and inf
values.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"f" : [None , "-inf" , "3.0" , "inf" , "nan" ]})
>>> t = t.mutate(f= ibis._.f.cast(float ))
>>> t.mutate(
... isnull= t.f.isnull(),
... isnan= t.f.isnan(),
... isinf= t.f.isinf(),
... )
βββββββββββ³ββββββββββ³ββββββββββ³ββββββββββ
β f β isnull β isnan β isinf β
β‘ββββββββββββββββββββββββββββββββββββββββ©
β float64 β boolean β boolean β boolean β
βββββββββββΌββββββββββΌββββββββββΌββββββββββ€
β NULL β True β NULL β NULL β
β -inf β False β False β True β
β 3.0 β False β False β False β
β inf β False β False β True β
β nan β False β True β False β
βββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ
BooleanValue
Methods
ifelse
Construct a ternary conditional expression.
negate
DEPRECATED.
ifelse
ifelse(true_expr, false_expr, / )
Construct a ternary conditional expression.
Parameters
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
Returns
Value
The value of true_expr
if arg
is True
else false_expr
Examples
>>> 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 β
ββββββββββββββββββββββββββββββββββ
BooleanColumn
Methods
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
.
all
Return whether all elements are True
.
Parameters
where
BooleanValue | None
Optional filter for the aggregation
None
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [1 , 2 , 3 , 4 ]})
>>> (t.arr >= 1 ).all ()
ββββββββ
β True β
ββββββββ
βββββββββ
β False β
βββββββββ
>>> (t.arr == 2 ).all (where= t.arr == 2 )
ββββββββ
β True β
ββββββββ
>>> (t.arr == 2 ).all (where= t.arr >= 2 )
βββββββββ
β False β
βββββββββ
any
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.
Parameters
where
BooleanValue | None
Optional filter for the aggregation
None
Notes
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
:
SELECT *
FROM t
WHERE EXISTS (SELECT 1 FROM s WHERE t.a = s.a)
Filtering from s
:
SELECT *
FROM s
WHERE EXISTS (SELECT 1 FROM t WHERE t.a = s.a)
Notably the correlated subquery cannot stand on its own.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [1 , 2 , 3 , None ]})
>>> (t.arr > 2 ).any ()
ββββββββ
β True β
ββββββββ
βββββββββ
β False β
βββββββββ
>>> (t.arr == None ).any (where= t.arr != None )
βββββββββ
β False β
βββββββββ
cumall
cumall(where= None , group_by= None , order_by= None )
Accumulate the all
aggregate.
Returns
BooleanColumn
A boolean column with the cumulative all
aggregate.
Examples
>>> 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 β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
>>> ((t.arr > 0 ) & (t.arr >= 1 )).cumall()
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β All(And(Greater(arr, 0), GreaterEqual(arr, 1))) β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββ©
β boolean β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β True β
β True β
β True β
β True β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
cumany
cumany(where= None , group_by= None , order_by= None )
Accumulate the any
aggregate.
Returns
BooleanColumn
A boolean column with the cumulative any
aggregate.
Examples
>>> 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 β
ββββββββββββββββββββββββββββββββββββββββββββββββββ
>>> ((t.arr > 1 ) & (t.arr >= 1 )).cumany()
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Any(And(Greater(arr, 1), GreaterEqual(arr, 1))) β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββ©
β boolean β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β False β
β True β
β True β
β True β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
notall
Return whether not all elements are True
.
Parameters
where
BooleanValue | None
Optional filter for the aggregation
None
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [1 , 2 , 3 , 4 ]})
>>> (t.arr >= 1 ).notall()
βββββββββ
β False β
βββββββββ
ββββββββ
β True β
ββββββββ
>>> (t.arr == 2 ).notall(where= t.arr == 2 )
βββββββββ
β False β
βββββββββ
>>> (t.arr == 2 ).notall(where= t.arr >= 2 )
ββββββββ
β True β
ββββββββ
notany
Return whether no elements are True
.
Parameters
where
BooleanValue | None
Optional filter for the aggregation
None
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [1 , 2 , 3 , 4 ]})
>>> (t.arr > 1 ).notany()
βββββββββ
β False β
βββββββββ
ββββββββ
β True β
ββββββββ
>>> m = ibis.memtable({"arr" : [True , True , True , False ]})
>>> (t.arr == None ).notany(where= t.arr != None )
ββββββββ
β True β
ββββββββ
and_
Combine multiple predicates using &
.
Parameters
predicates
ir
.BooleanValue
Boolean value expressions
()
Returns
BooleanValue
A new predicate that evaluates to True if all composing predicates are True. If no predicates were provided, returns True.
or_
Combine multiple predicates using |
.
Parameters
predicates
ir
.BooleanValue
Boolean value expressions
()
Returns
BooleanValue
A new predicate that evaluates to True if any composing predicates are True. If no predicates were provided, returns False.
random
Return a random floating point number in the range [0.0, 1.0).
Similar to random.random
in the Python standard library.
ibis.random()
will generate a column of distinct random numbers even if the same instance of ibis.random()
is reused.
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 β
βββββββββ΄βββββββββββ΄βββββββββββ
Returns
FloatingScalar
Random float value expression
Back to top