PyLegendBoolean
Boolean expression type in the PyLegend expression language.
PyLegendBoolean represents a boolean-valued column or computed
expression within a PyLegend query. It supports the standard logical
operators (&, |, ~, ^), comparison operators
(<, <=, >, >=), and conditional branching via
case().
Instances are never constructed directly. They are produced by
operations on TDS frame columns — for example, comparing a column
to a literal (frame["Age"] > 30) or accessing a boolean column
through a row accessor (row.get_boolean("is_active")).
PyLegendBoolean also inherits general-purpose methods from
PyLegendPrimitive, including equality / inequality tests, null checks,
string conversion, and in_list.
__and__
- PyLegendBoolean.__and__(other)[source]
Logical AND (
&).Combine two boolean expressions with a logical AND.
- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhere both operands areTrue.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Orders with id >= 10250 AND id <= 10260 cond = (frame["Order Id"] >= 10250) & (frame["Order Id"] <= 10260) frame[cond].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
__eq__
- PyLegendPrimitive.__eq__(other)[source]
Test element-wise equality (
==).Compare this expression against another primitive value or expression. Returns a boolean expression that is
Truewhere 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
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
__ge__
- PyLegendBoolean.__ge__(other)[source]
Greater than or equal comparison (
>=).- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhereself >= other.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["ge_check"] = (frame["Order Id"] > 10250) >= (frame["Order Id"] > 10260) frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name ge_check 0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier True 1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten True 2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes True
__gt__
- PyLegendBoolean.__gt__(other)[source]
Greater than comparison (
>).- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhereself > other.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["gt_check"] = (frame["Order Id"] > 10250) > (frame["Order Id"] > 10260) frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name gt_check 0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier False 1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten False 2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes False
__invert__
- PyLegendBoolean.__invert__()[source]
Logical NOT (
~).Negate this boolean expression.
- Returns:
Truewhere the original expression isFalse, and vice-versa.- Return type:
PyLegendBoolean
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Negate a condition frame[~(frame["Order Id"] > 10255)].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
__le__
- PyLegendBoolean.__le__(other)[source]
Less than or equal comparison (
<=).- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhereself <= other.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["le_check"] = (frame["Order Id"] > 10260) <= (frame["Order Id"] > 10250) frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name le_check 0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier True 1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten True 2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes True
__lt__
- PyLegendBoolean.__lt__(other)[source]
Less than comparison (
<).- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhereself < other.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Compare two boolean expressions: is (id > 10260) < (id > 10250)? frame["lt_check"] = (frame["Order Id"] > 10260) < (frame["Order Id"] > 10250) frame.head(3).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name lt_check 0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier False 1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten False 2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes False
__ne__
- PyLegendPrimitive.__ne__(other)[source]
Test element-wise inequality (
!=).Compare this expression against another primitive value or expression. Returns a boolean expression that is
Truewhere 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
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
__or__
- PyLegendBoolean.__or__(other)[source]
Logical OR (
|).Combine two boolean expressions with a logical OR.
- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhere either operand isTrue.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Orders with id < 10250 OR id > 10260 cond = (frame["Order Id"] < 10250) | (frame["Order Id"] > 10260) frame[cond].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 10261 1996-07-19 1996-08-16 1996-07-30 Que Delícia
__rand__
- PyLegendBoolean.__rand__(other)[source]
Reflected logical AND (
bool & expr).Called when a Python
boolliteral is on the left side of&. Behaves identically to__and__()with swapped operand order.- Parameters:
other (
Union[bool,PyLegendBoolean]) – The left-hand operand.- Returns:
Truewhere both operands areTrue.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
__ror__
- PyLegendBoolean.__ror__(other)[source]
Reflected logical OR (
bool | expr).Called when a Python
boolliteral is on the left side of|. Behaves identically to__or__()with swapped operand order.- Parameters:
other (
Union[bool,PyLegendBoolean]) – The left-hand operand.- Returns:
Truewhere either operand isTrue.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
__rxor__
- PyLegendBoolean.__rxor__(other)[source]
Reflected logical XOR (
bool ^ expr).Called when a Python
boolliteral is on the left side of^. Behaves identically to__xor__()with swapped operand order.- Parameters:
other (
Union[bool,PyLegendBoolean]) – The left-hand operand.- Returns:
Truewhere exactly one operand isTrue.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
__xor__
- PyLegendBoolean.__xor__(other)[source]
Logical XOR (
^).Exclusive OR —
Truewhen exactly one operand isTrue. Translates to SQL<>and Pure->xor().- Parameters:
other (
Union[bool,PyLegendBoolean]) – The right-hand operand.- Returns:
Truewhere exactly one operand isTrue.- Return type:
PyLegendBoolean- Raises:
TypeError – If other is not a
boolorPyLegendBoolean.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
# XOR two conditions cond = (frame["Order Id"] > 10255) ^ (frame["Order Id"] < 10250) frame[cond].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
case
- PyLegendBoolean.case(if_true, if_false)[source]
Conditional expression — SQL
CASE WHEN … THEN … ELSE … END.Evaluate this boolean expression and return if_true where it is
True, or if_false where it isFalse.Both branches must resolve to the same type family (e.g. both numeric, both string, both date). The return type of the resulting expression matches that family.
- Parameters:
if_true (
Union[int,float,str,bool,date,datetime,Decimal,PyLegendPrimitive]) – Value returned when the condition isTrue.if_false (
Union[int,float,str,bool,date,datetime,Decimal,PyLegendPrimitive]) – Value returned when the condition isFalse.
- Returns:
An expression whose concrete type depends on the branch values (e.g.
PyLegendIntegerif both branches are integers,PyLegendStringif both are strings).- Return type:
PyLegendPrimitive- Raises:
TypeError – If if_true or if_false is not a supported primitive type, or if the two branches have incompatible types.
Examples
import pylegend frame = pylegend.samples.pandas_api.northwind_orders_frame()
# Classify orders by size frame["size"] = (frame["Order Id"] > 10250).case("large", "small") frame.head(5).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name size 0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier small 1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten small 2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes small 3 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock large 4 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices large # Numeric branch — compute a bonus frame["bonus"] = (frame["Order Id"] > 10250).case(100, 0) frame.head(5).to_pandas()
Order Id Order Date Required Date Shipped Date Ship Name size bonus 0 10248 1996-07-04 1996-08-01 1996-07-16 Vins et alcools Chevalier small 0 1 10249 1996-07-05 1996-08-16 1996-07-10 Toms Spezialitäten small 0 2 10250 1996-07-08 1996-08-05 1996-07-12 Hanari Carnes small 0 3 10251 1996-07-08 1996-08-05 1996-07-15 Victuailles en stock large 100 4 10252 1996-07-09 1996-08-06 1996-07-11 Suprêmes délices large 100
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:
Truewhere 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
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
Truewhere the underlying column value isNULL.- Returns:
Truewhere the value is null.- Return type:
PyLegendBoolean
See also
is_not_emptyThe inverse test.
is_nullAlias for
is_empty.
Examples
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
Truewhere the underlying column value is notNULL.- Returns:
Truewhere the value is not null.- Return type:
PyLegendBoolean
See also
is_emptyThe inverse test.
is_not_nullAlias for
is_not_empty.
Examples
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:
Truewhere the value is not null.- Return type:
PyLegendBoolean
See also
is_not_emptyCanonical not-null-check method.
is_nullThe inverse test.
is_null
- PyLegendPrimitive.is_null()[source]
Test whether the value is null.
Alias for
is_empty().- Returns:
Truewhere the value is null.- Return type:
PyLegendBoolean
See also
is_emptyCanonical null-check method.
is_not_nullThe inverse test.
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
toStringAlias for
to_string.
Examples
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_stringCanonical string-conversion method.