Math#

Function

Description

ABS

Returns the absolute value of the input column.

CBRT

Returns the cube root (βˆ›) of a number.

CEIL

Returns the nearest integer closest from zero.

DIV

Returns the integer quotient of the division.

EXP

Computes the exponential of the given value.

FLOOR

Returns the nearest integer away from zero.

LN

Computes the natural logarithm of the given value.

LOG

Computes the base logarithm of the given value.

LOG2

Computes the logarithm of the given value in base 2.

LOG10

Computes the logarithm of the given value in base 10.

LOG1P

Computes the natural logarithm of β€œgiven value plus one”.

MOD

Returns the remainder of a numeric expression divided by another numeric expression.

PI

Returns a (very good) approximation of πœ‹.

POW

Returns the value to the power of the given exponent.

ROUND

Round a number to x decimals (default: 0) away from zero.

SIGN

Returns the sign of the argument as -1, 0, or +1.

SQRT

Returns the square root (√) of a number.

ABS#

Returns the absolute value of the input column.

Example:

df = pl.DataFrame({"a": [-1.0, 0.0, 1.0, -2.0]})
df.sql("""
  SELECT a, ABS(a) AS abs_a FROM self
""")
# shape: (4, 2)
# β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a    ┆ abs_a β”‚
# β”‚ ---  ┆ ---   β”‚
# β”‚ f64  ┆ f64   β”‚
# β•žβ•β•β•β•β•β•β•ͺ═══════║
# β”‚ -1.0 ┆ 1.0   β”‚
# β”‚ 0.0  ┆ 0.0   β”‚
# β”‚ 1.0  ┆ 1.0   β”‚
# β”‚ -2.0 ┆ 2.0   β”‚
# β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

CBRT#

Returns the cube root (βˆ›) of a number.

Example:

df = pl.DataFrame({"a": [1.0, 2.0, 4.0]})
df.sql("""
  SELECT a, CBRT(a) AS cbrt_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ cbrt_a   β”‚
# β”‚ --- ┆ ---      β”‚
# β”‚ f64 ┆ f64      β”‚
# β•žβ•β•β•β•β•β•ͺ══════════║
# β”‚ 1.0 ┆ 1.0      β”‚
# β”‚ 2.0 ┆ 1.259921 β”‚
# β”‚ 4.0 ┆ 1.587401 β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

CEIL#

Returns the nearest integer closest from zero.

Example:

df = pl.DataFrame({"a": [0.1, 2.8, 4.30]})
df.sql("""
  SELECT a, CEIL(a) AS ceil_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ ceil_a β”‚
# β”‚ --- ┆ ---    β”‚
# β”‚ f64 ┆ f64    β”‚
# β•žβ•β•β•β•β•β•ͺ════════║
# β”‚ 0.1 ┆ 1.0    β”‚
# β”‚ 2.8 ┆ 3.0    β”‚
# β”‚ 4.3 ┆ 5.0    β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

DIV#

Returns the integer quotient of the division.

Example:

df = pl.DataFrame({"a": [-10.0, 6.5, 25.0]})
df.sql("""
  SELECT a, DIV(a, 2) AS a_div_2, DIV(a, 5) AS a_div_5 FROM self
""")
# shape: (3, 3)
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a     ┆ a_div_2 ┆ a_div_5 β”‚
# β”‚ ---   ┆ ---     ┆ ---     β”‚
# β”‚ f64   ┆ i64     ┆ i64     β”‚
# β•žβ•β•β•β•β•β•β•β•ͺ═════════β•ͺ═════════║
# β”‚ -10.0 ┆ -5      ┆ -2      β”‚
# β”‚ 6.5   ┆ 3       ┆ 1       β”‚
# β”‚ 25.0  ┆ 12      ┆ 5       β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

EXP#

Computes the exponential of the given value.

Example:

df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
  SELECT a, EXP(a) AS exp_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ exp_a    β”‚
# β”‚ --- ┆ ---      β”‚
# β”‚ i64 ┆ f64      β”‚
# β•žβ•β•β•β•β•β•ͺ══════════║
# β”‚ 1   ┆ 2.718282 β”‚
# β”‚ 2   ┆ 7.389056 β”‚
# β”‚ 4   ┆ 54.59815 β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

FLOOR#

Returns the nearest integer away from zero.

Example:

df = pl.DataFrame({"a": [0.1, 2.8, 4.30]})
df.sql("""
  SELECT a, FLOOR(a) AS floor_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ floor_a β”‚
# β”‚ --- ┆ ---     β”‚
# β”‚ f64 ┆ f64     β”‚
# β•žβ•β•β•β•β•β•ͺ═════════║
# β”‚ 0.1 ┆ 0.0     β”‚
# β”‚ 2.8 ┆ 2.0     β”‚
# β”‚ 4.3 ┆ 4.0     β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LN#

Computes the natural logarithm of the given value.

Example:

df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
  SELECT a, LN(a) AS ln_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ ln_a     β”‚
# β”‚ --- ┆ ---      β”‚
# β”‚ i64 ┆ f64      β”‚
# β•žβ•β•β•β•β•β•ͺ══════════║
# β”‚ 1   ┆ 0.0      β”‚
# β”‚ 2   ┆ 0.693147 β”‚
# β”‚ 4   ┆ 1.386294 β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LOG#

Computes the base logarithm of the given value.

Example:

df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
  SELECT a, LOG(a, 16) AS log16_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ log16_a β”‚
# β”‚ --- ┆ ---     β”‚
# β”‚ i64 ┆ f64     β”‚
# β•žβ•β•β•β•β•β•ͺ═════════║
# β”‚ 1   ┆ 0.0     β”‚
# β”‚ 2   ┆ 0.25    β”‚
# β”‚ 4   ┆ 0.5     β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LOG2#

Computes the logarithm of the given value in base 2.

Example:

df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
  SELECT a, LOG2(a) AS a_log2 FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ a_log2 β”‚
# β”‚ --- ┆ ---    β”‚
# β”‚ i64 ┆ f64    β”‚
# β•žβ•β•β•β•β•β•ͺ════════║
# β”‚ 1   ┆ 0.0    β”‚
# β”‚ 2   ┆ 1.0    β”‚
# β”‚ 4   ┆ 2.0    β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LOG10#

Computes the logarithm of the given value in base 10.

Example:

df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
  SELECT a, LOG10(a) AS log10_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ log10_a β”‚
# β”‚ --- ┆ ---     β”‚
# β”‚ i64 ┆ f64     β”‚
# β•žβ•β•β•β•β•β•ͺ═════════║
# β”‚ 1   ┆ 0.0     β”‚
# β”‚ 2   ┆ 0.30103 β”‚
# β”‚ 4   ┆ 0.60206 β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

LOG1P#

Computes the natural logarithm of β€œgiven value plus one”.

Example:

df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
  SELECT a, LOG1P(a) AS log1p_a FROM self
""")
# shape: (3, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ a   ┆ log1p_a  β”‚
# β”‚ --- ┆ ---      β”‚
# β”‚ i64 ┆ f64      β”‚
# β•žβ•β•β•β•β•β•ͺ══════════║
# β”‚ 1   ┆ 0.693147 β”‚
# β”‚ 2   ┆ 1.098612 β”‚
# β”‚ 4   ┆ 1.609438 β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

MOD#

Returns the remainder of a numeric expression divided by another numeric expression.

Example:

df = pl.DataFrame({"x": [0, 1, 2, 3, 4]})
df.sql("""
  SELECT x, MOD(x, 2) AS a_mod_2 FROM self
""")
# shape: (5, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ x   ┆ a_mod_2 β”‚
# β”‚ --- ┆ ---     β”‚
# β”‚ i64 ┆ i64     β”‚
# β•žβ•β•β•β•β•β•ͺ═════════║
# β”‚ 0   ┆ 0       β”‚
# β”‚ 1   ┆ 1       β”‚
# β”‚ 2   ┆ 0       β”‚
# β”‚ 3   ┆ 1       β”‚
# β”‚ 4   ┆ 0       β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

PI#

Returns a (good) approximation of πœ‹.

Example:

df.sql("""
  SELECT PI() AS pi FROM self
""")
# shape: (1, 1)
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ pi       β”‚
# β”‚ ---      β”‚
# β”‚ f64      β”‚
# β•žβ•β•β•β•β•β•β•β•β•β•β•‘
# β”‚ 3.141593 β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

POW#

Returns the value to the power of the given exponent.

Example:

df = pl.DataFrame({"x": [0, 1, 2, 4]})
df.sql("""
  SELECT x, POW(x, 8) AS x_pow_8 FROM self
""")
# shape: (4, 2)
# β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ x   ┆ x_pow_8 β”‚
# β”‚ --- ┆ ---     β”‚
# β”‚ i64 ┆ i64     β”‚
# β•žβ•β•β•β•β•β•ͺ═════════║
# β”‚ 0   ┆ 0       β”‚
# β”‚ 1   ┆ 1       β”‚
# β”‚ 2   ┆ 256     β”‚
# β”‚ 4   ┆ 65536   β”‚
# β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

ROUND#

Round a number to x decimals (default: 0) away from zero.

Example:

df = pl.DataFrame({"x": [-0.45, -1.81, 2.25, 3.99]})
df.sql("""
  SELECT x, ROUND(x) AS x_round, ROUND(x, 1) AS x_round_1 FROM self
""")
# shape: (4, 3)
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ x     ┆ x_round ┆ x_round_1 β”‚
# β”‚ ---   ┆ ---     ┆ ---       β”‚
# β”‚ f64   ┆ f64     ┆ f64       β”‚
# β•žβ•β•β•β•β•β•β•β•ͺ═════════β•ͺ═══════════║
# β”‚ -0.45 ┆ -0.0    ┆ -0.5      β”‚
# β”‚ -1.81 ┆ -2.0    ┆ -1.8      β”‚
# β”‚ 2.25  ┆ 2.0     ┆ 2.3       β”‚
# β”‚ 3.99  ┆ 4.0     ┆ 4.0       β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SIGN#

Returns the sign of the argument as -1, 0, or +1.

Example:

df = pl.DataFrame({"x": [0.4, -1, 0, -2, 4]})
df.sql("""
  SELECT x, SIGN(x) AS sign_x FROM self
""")
# shape: (5, 2)
# β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ x    ┆ sign_x β”‚
# β”‚ ---  ┆ ---    β”‚
# β”‚ f64  ┆ i64    β”‚
# β•žβ•β•β•β•β•β•β•ͺ════════║
# β”‚ 0.4  ┆ 1      β”‚
# β”‚ -1.0 ┆ -1     β”‚
# β”‚ 0.0  ┆ 0      β”‚
# β”‚ -2.0 ┆ -1     β”‚
# β”‚ 4.0  ┆ 1      β”‚
# β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SQRT#

Returns the square root (√) of a number.

Example:

df = pl.DataFrame({"x": [2, 16, 4096, 65536]})
df.sql("""
  SELECT x, SQRT(x) AS sqrt_x FROM self
""")
# shape: (4, 2)
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ x     ┆ sqrt_x   β”‚
# β”‚ ---   ┆ ---      β”‚
# β”‚ i64   ┆ f64      β”‚
# β•žβ•β•β•β•β•β•β•β•ͺ══════════║
# β”‚ 2     ┆ 1.414214 β”‚
# β”‚ 16    ┆ 4.0      β”‚
# β”‚ 4096  ┆ 64.0     β”‚
# β”‚ 65536 ┆ 256.0    β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜