PyLegendNumber

Numeric expression type in the PyLegend expression language.

PyLegendNumber is the base class for all numeric column expressions (PyLegendInteger, PyLegendFloat, PyLegendDecimal). It supports the standard arithmetic operators (+, -, *, /, **), comparison operators (<, <=, >, >=), unary operators (+, -, abs()), rounding/ceiling/floor, and a wide range of mathematical functions (trigonometric, logarithmic, hyperbolic, etc.).

Instances are never constructed directly. They are produced by accessing a numeric column on a TDS frame — for example, frame["Order Id"] — or by arithmetic on existing numeric expressions.

PyLegendNumber also inherits general-purpose methods from PyLegendPrimitive, including equality / inequality tests, null checks, string conversion, and in_list.

__abs__

PyLegendNumber.__abs__()[source]

Absolute value (abs(expr)).

Returns:

The absolute value expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["abs_id"] = abs(frame["Order Id"])
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name abs_id
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 10248
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 10249
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 10250

__add__

PyLegendNumber.__add__(other)[source]

Addition (+).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

The sum expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_plus_10"] = frame["Order Id"] + 10
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_plus_10
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 10258
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 10259
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 10260

__ceil__

PyLegendNumber.__ceil__()[source]

Ceiling via math.ceil().

Alias for ceil().

Returns:

The ceiling expression.

Return type:

PyLegendInteger

See also

ceil

Canonical ceiling method.

__eq__

PyLegendPrimitive.__eq__(other)[source]

Test element-wise equality (==).

Compare this expression against another primitive value or expression. Returns a boolean expression that is True where the values are equal.

Parameters:

other (Union[int, float, bool, str, date, datetime, Decimal, PyLegendPrimitive]) – The value or expression to compare against.

Returns:

A boolean expression representing the equality test.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported primitive type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Filter rows where Ship Name equals a literal
frame[frame["Ship Name"] == "Around the Horn"].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10355 1996-11-15 1996-12-13 1996-11-20 Around the Horn
1 10383 1996-12-16 1997-01-13 1996-12-18 Around the Horn
2 10453 1997-02-21 1997-03-21 1997-02-26 Around the Horn

__floor__

PyLegendNumber.__floor__()[source]

Floor via math.floor().

Alias for floor().

Returns:

The floor expression.

Return type:

PyLegendInteger

See also

floor

Canonical floor method.

__ge__

PyLegendNumber.__ge__(other)[source]

Greater than or equal comparison (>=).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

True where self >= other.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Order Id"] >= 10250].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes
1 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock
2 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices

__gt__

PyLegendNumber.__gt__(other)[source]

Greater than comparison (>).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

True where self > other.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Order Id"] > 10250].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock
1 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices
2 10253 1996-07-10 1996-07-24 1996-07-16 Hanari Carnes

__le__

PyLegendNumber.__le__(other)[source]

Less than or equal comparison (<=).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

True where self <= other.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Order Id"] <= 10250].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

__lt__

PyLegendNumber.__lt__(other)[source]

Less than comparison (<).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

True where self < other.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame[frame["Order Id"] < 10250].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten

__mul__

PyLegendNumber.__mul__(other)[source]

Multiplication (*).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

The product expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_times_2"] = frame["Order Id"] * 2
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_times_2
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 20496
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 20498
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 20500

__ne__

PyLegendPrimitive.__ne__(other)[source]

Test element-wise inequality (!=).

Compare this expression against another primitive value or expression. Returns a boolean expression that is True where the values differ.

Parameters:

other (Union[int, float, bool, str, date, datetime, Decimal, PyLegendPrimitive]) – The value or expression to compare against.

Returns:

A boolean expression representing the inequality test.

Return type:

PyLegendBoolean

Raises:

TypeError – If other is not a supported primitive type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Filter rows where Ship Name is not a specific value
frame[frame["Ship Name"] != "Ship1"].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

__neg__

PyLegendNumber.__neg__()[source]

Unary negation (-expr).

Returns:

The negated expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["neg_id"] = -frame["Order Id"]
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name neg_id
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier -10248
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten -10249
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes -10250

__pos__

PyLegendNumber.__pos__()[source]

Unary positive (+expr).

Returns the expression unchanged. Included for operator completeness.

Returns:

The same expression.

Return type:

PyLegendNumber

__pow__

PyLegendNumber.__pow__(other)[source]

Power / exponentiation (**).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The exponent.

Returns:

The power expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_squared"] = frame["Order Id"] ** 2
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_squared
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 105021504.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 105042001.0
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 105062500.0

__radd__

PyLegendNumber.__radd__(other)[source]

Reflected addition (int + expr).

Called when a Python literal is on the left side of +. Behaves identically to __add__() with swapped operand order.

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The left-hand operand.

Returns:

The sum expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

__rmul__

PyLegendNumber.__rmul__(other)[source]

Reflected multiplication (int * expr).

Called when a Python literal is on the left side of *. Behaves identically to __mul__() with swapped operand order.

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The left-hand operand.

Returns:

The product expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

__round__

PyLegendNumber.__round__(n=None)[source]

Round via built-in round().

Alias for round().

Parameters:

n (Optional[int]) – Number of decimal places.

Returns:

The rounded expression.

Return type:

PyLegendNumber

See also

round

Canonical rounding method.

__rpow__

PyLegendNumber.__rpow__(other)[source]

Reflected power (int ** expr).

Called when a Python literal is on the left side of **. Behaves identically to __pow__() with swapped operand order.

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The base (left-hand operand).

Returns:

The power expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

__rsub__

PyLegendNumber.__rsub__(other)[source]

Reflected subtraction (int - expr).

Called when a Python literal is on the left side of -. Behaves identically to __sub__() with swapped operand order.

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The left-hand operand (minuend).

Returns:

The difference expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

__rtruediv__

PyLegendNumber.__rtruediv__(other)[source]

Reflected true division (int / expr).

Called when a Python literal is on the left side of /. Behaves identically to __truediv__() with swapped operand order.

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The dividend (left-hand operand).

Returns:

The quotient expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

__sub__

PyLegendNumber.__sub__(other)[source]

Subtraction (-).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The right-hand operand.

Returns:

The difference expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_minus_10000"] = frame["Order Id"] - 10000
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_minus_10000
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 248
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 249
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 250

__truediv__

PyLegendNumber.__truediv__(other)[source]

True division (/).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The divisor.

Returns:

The quotient expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_half"] = frame["Order Id"] / 2
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_half
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 5124.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 5124.5
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 5125.0

acos

PyLegendNumber.acos()[source]

Arc-cosine (inverse cosine). Result in radians.

Returns:

The arc-cosine expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_acos"] = (frame["Order Id"] - 10248).acos()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_acos
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 1.570796
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 0.0
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes <NA>

asin

PyLegendNumber.asin()[source]

Arc-sine (inverse sine). Result in radians.

Returns:

The arc-sine expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_asin"] = (frame["Order Id"] - 10248).asin()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_asin
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 1.570796
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes <NA>

atan

PyLegendNumber.atan()[source]

Arc-tangent (inverse tangent). Result in radians.

Returns:

The arc-tangent expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_atan"] = frame["Order Id"].atan()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_atan
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 1.570699
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 1.570699
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 1.570699

atan2

PyLegendNumber.atan2(other)[source]

Two-argument arc-tangent (atan2(self, other)).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The second argument (x-coordinate).

Returns:

The arc-tangent expression (result in radians).

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_atan2"] = frame["Order Id"].atan2(10000)
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_atan2
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.797646
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 0.797694
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 0.797743

cbrt

PyLegendNumber.cbrt()[source]

Cube root.

Returns:

The cube-root expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_cbrt"] = frame["Order Id"].cbrt()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_cbrt
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 21.720994
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 21.721701
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 21.722407

ceil

PyLegendNumber.ceil()[source]

Ceiling — smallest integer greater than or equal to the value.

Returns:

The ceiling expression.

Return type:

PyLegendInteger

See also

floor

The opposite rounding direction.

__ceil__

Alias called by math.ceil().

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_ceil"] = (frame["Order Id"] / 3).ceil()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_ceil
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 3416
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 3417
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 3417

cos

PyLegendNumber.cos()[source]

Cosine (input in radians).

Returns:

The cosine expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_cos"] = frame["Order Id"].cos()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_cos
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.992227
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 0.431389
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes -0.526066

cosh

PyLegendNumber.cosh()[source]

Hyperbolic cosine.

Returns:

The hyperbolic cosine expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_cosh"] = (frame["Order Id"] - 10248).cosh()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_cosh
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 1.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 1.543081
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 3.762196

cot

PyLegendNumber.cot()[source]

Cotangent (input in radians).

Returns:

The cotangent expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_cot"] = frame["Order Id"].cot()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_cot
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 7.973502
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 0.478171
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes -0.618578

degrees

PyLegendNumber.degrees()[source]

Convert radians to degrees.

Returns:

The value in degrees.

Return type:

PyLegendNumber

See also

radians

The inverse conversion.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_deg"] = frame["Order Id"].degrees()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_deg
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 587167.14845
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 587224.44423
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 587281.740009

exp

PyLegendNumber.exp()[source]

Natural exponential (e ** x).

Returns:

The exponential expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_exp"] = (frame["Order Id"] - 10248).exp()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_exp
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 1.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 2.718282
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 7.389056

floor

PyLegendNumber.floor()[source]

Floor — largest integer less than or equal to the value.

Returns:

The floor expression.

Return type:

PyLegendInteger

See also

ceil

The opposite rounding direction.

__floor__

Alias called by math.floor().

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_floor"] = (frame["Order Id"] / 3).floor()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_floor
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 3416
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 3416
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 3416

in_list

PyLegendPrimitive.in_list(lst)[source]

Test whether the value is contained in a list of values.

Returns a boolean expression equivalent to SQL IN (...).

Parameters:

lst (List[Union[int, float, bool, str, date, datetime, Decimal, PyLegendPrimitive]]) – A non-empty list of literal values or expressions to check membership against.

Returns:

True where the value matches any element in lst.

Return type:

PyLegendBoolean

Raises:
  • ValueError – If lst is not a list or is empty.

  • TypeError – If any element in lst is not a supported primitive type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Keep rows where Ship Name is one of several values
frame[
    frame["Ship Name"].in_list(["Hanari Carnes", "Victuailles en stock", "Suprêmes délices"])
].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes
1 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock
2 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices

is_empty

PyLegendPrimitive.is_empty()[source]

Test whether the value is null / empty.

Returns a boolean expression that is True where the underlying column value is NULL.

Returns:

True where the value is null.

Return type:

PyLegendBoolean

See also

is_not_empty

The inverse test.

is_null

Alias for is_empty.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Keep only rows where Ship Name is null
frame[frame["Shipped Date"].is_empty()].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 11008 1998-04-08 1998-05-06 NaT Ernst Handel
1 11019 1998-04-13 1998-05-11 NaT Rancho grande
2 11039 1998-04-21 1998-05-19 NaT LINO-Delicateses

is_not_empty

PyLegendPrimitive.is_not_empty()[source]

Test whether the value is not null / not empty.

Returns a boolean expression that is True where the underlying column value is not NULL.

Returns:

True where the value is not null.

Return type:

PyLegendBoolean

See also

is_empty

The inverse test.

is_not_null

Alias for is_not_empty.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Keep only rows where Ship Name is present
frame[frame["Ship Name"].is_not_empty()].head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes

is_not_null

PyLegendPrimitive.is_not_null()[source]

Test whether the value is not null.

Alias for is_not_empty().

Returns:

True where the value is not null.

Return type:

PyLegendBoolean

See also

is_not_empty

Canonical not-null-check method.

is_null

The inverse test.

is_null

PyLegendPrimitive.is_null()[source]

Test whether the value is null.

Alias for is_empty().

Returns:

True where the value is null.

Return type:

PyLegendBoolean

See also

is_empty

Canonical null-check method.

is_not_null

The inverse test.

log

PyLegendNumber.log()[source]

Natural logarithm (ln(x)).

Returns:

The natural-log expression.

Return type:

PyLegendNumber

See also

log10

Base-10 logarithm.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_log"] = frame["Order Id"].log()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_log
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 9.234838
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 9.234935
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 9.235033

log10

PyLegendNumber.log10()[source]

Base-10 logarithm.

Returns:

The base-10 logarithm expression.

Return type:

PyLegendNumber

See also

log

Natural logarithm.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_log10"] = frame["Order Id"].log10()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_log10
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 4.010639
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 4.010681
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 4.010724

radians

PyLegendNumber.radians()[source]

Convert degrees to radians.

Returns:

The value in radians.

Return type:

PyLegendNumber

See also

degrees

The inverse conversion.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_rad"] = frame["Order Id"].radians()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_rad
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 178.861342
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 178.878795
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 178.896248

rem

PyLegendNumber.rem(other)[source]

Remainder (modulo for numeric expressions).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendNumber]) – The divisor.

Returns:

The remainder expression.

Return type:

PyLegendNumber

Raises:

TypeError – If other is not a supported numeric type.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_rem_3"] = frame["Order Id"].rem(3)
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_rem_3
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 1.0
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 2.0

round

PyLegendNumber.round(n=None)[source]

Round to n decimal places.

Parameters:

n (Optional[int]) – Number of decimal places. Defaults to 0 (round to nearest integer).

Returns:

The rounded expression.

Return type:

PyLegendNumber

Raises:

TypeError – If n is not an int.

See also

__round__

Alias called by round().

ceil

Round up.

floor

Round down.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_round"] = (frame["Order Id"] / 3).round(2)
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_round
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 3416.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 3416.33
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 3416.67

sign

PyLegendNumber.sign()[source]

Sign of the value (-1, 0, or 1).

Returns:

-1 for negative, 0 for zero, 1 for positive.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_sign"] = (frame["Order Id"] - 10255).sign()
frame.head(5).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_sign
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier -1.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten -1.0
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes -1.0
3 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock -1.0
4 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices -1.0

sin

PyLegendNumber.sin()[source]

Sine (input in radians).

Returns:

The sine expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_sin"] = frame["Order Id"].sin()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_sin
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.124441
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 0.902166
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 0.850444

sinh

PyLegendNumber.sinh()[source]

Hyperbolic sine.

Returns:

The hyperbolic sine expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_sinh"] = (frame["Order Id"] - 10248).sinh()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_sinh
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 1.175201
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 3.62686

sqrt

PyLegendNumber.sqrt()[source]

Square root.

Returns:

The square-root expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_sqrt"] = frame["Order Id"].sqrt()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_sqrt
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 101.232406
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 101.237345
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 101.242284

tan

PyLegendNumber.tan()[source]

Tangent (input in radians).

Returns:

The tangent expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_tan"] = frame["Order Id"].tan()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_tan
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.125415
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 2.091302
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes -1.616612

tanh

PyLegendNumber.tanh()[source]

Hyperbolic tangent.

Returns:

The hyperbolic tangent expression.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_tanh"] = (frame["Order Id"] - 10248).tanh()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_tanh
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 0.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 0.761594
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 0.964028

to_decimal

PyLegendNumber.to_decimal()[source]

Cast the value to a decimal expression.

Returns:

The value as a decimal expression.

Return type:

PyLegendDecimal

See also

to_float

Cast to float instead.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_decimal"] = frame["Order Id"].to_decimal()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_decimal
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 10248
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 10249
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 10250

to_float

PyLegendNumber.to_float()[source]

Cast the value to a float expression.

Returns:

The value as a float expression.

Return type:

PyLegendFloat

See also

to_decimal

Cast to decimal instead.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_float"] = frame["Order Id"].to_float()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name id_float
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 10248.0
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 10249.0
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 10250.0

to_string

PyLegendPrimitive.to_string()[source]

Convert the value to its string representation.

Returns a string expression produced by applying the database’s CAST(... AS TEXT) (SQL) or ->toString() (Pure).

Returns:

The stringified expression.

Return type:

PyLegendString

See also

toString

Alias for to_string.

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Convert an integer column to a string
frame["order_str"] = frame["Order Id"].to_string()
frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name order_str
0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier 10248
1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten 10249
2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes 10250

toString

PyLegendPrimitive.toString()[source]

Convert the value to its string representation.

Alias for to_string().

Returns:

The stringified expression.

Return type:

PyLegendString

See also

to_string

Canonical string-conversion method.