Conditional Functions
Functions for conditional logic and control flow in data processing.
conditional
and_
and_(*args: Union[ColumnElement, Func]) -> Func
Returns the function that produces conjunction of expressions joined by AND logical operator.
Parameters:
-
args
(ColumnElement | Func
, default:()
) βThe expressions for AND statement. If a string is provided, it is assumed to be the name of the column. If a Column is provided, it is assumed to be a column in the dataset. If a Func is provided, it is assumed to be a function returning a value.
Returns:
-
Func
(Func
) βA
Func
object that represents the AND function.
Notes
- The result column will always be of type bool.
Source code in datachain/func/conditional.py
case
case(
*args: tuple[Union[ColumnElement, Func, bool], CaseT],
else_: Optional[CaseT] = None
) -> Func
Returns a case expression that evaluates a list of conditions and returns corresponding results. Results can be Python primitives (string, numbers, booleans), nested functions (including case function), or columns.
Parameters:
-
args
(tuple[ColumnElement | Func | bool, CaseT]
, default:()
) βTuples of (condition, value) pairs. Each condition is evaluated in order, and the corresponding value is returned for the first condition that evaluates to True.
-
else_
(CaseT
, default:None
) βValue to return if no conditions are satisfied. If omitted and no conditions are satisfied, the result will be None (NULL in DB).
Returns:
-
Func
(Func
) βA
Func
object that represents the case function.
Notes
- The result type is inferred from the values provided in the case statements.
Source code in datachain/func/conditional.py
greatest
Returns the greatest (largest) value from the given input values.
Parameters:
-
args
(str | Column | Func | int | float
, default:()
) βThe values to compare. If a string is provided, it is assumed to be the name of the column. If a Column is provided, it is assumed to be a column in the dataset. If a Func is provided, it is assumed to be a function returning a value. If an int or float is provided, it is assumed to be a literal.
Returns:
-
Func
(Func
) βA
Func
object that represents the greatest function.
Notes
- The result column will always be of the same type as the input columns.
Source code in datachain/func/conditional.py
ifelse
ifelse(
condition: Union[ColumnElement, Func],
if_val: CaseT,
else_val: CaseT,
) -> Func
Returns an if-else expression that evaluates a condition and returns one of two values based on the result. Values can be Python primitives (string, numbers, booleans), nested functions, or columns.
Parameters:
-
condition
(ColumnElement | Func
) βCondition to evaluate.
-
if_val
(ColumnElement | Func | literal
) βValue to return if condition is True.
-
else_val
(ColumnElement | Func | literal
) βValue to return if condition is False.
Returns:
-
Func
(Func
) βA
Func
object that represents the ifelse function.
Notes
- The result type is inferred from the values provided in the ifelse statement.
Source code in datachain/func/conditional.py
isnone
Returns a function that checks if the column value is None
(NULL in DB).
Parameters:
-
col
(str | Column
) βColumn to check if it's None or not. If a string is provided, it is assumed to be the name of the column. If a Column is provided, it is assumed to be a column in the dataset.
Returns:
-
Func
(Func
) βA
Func
object that represents the isnone function. Returns True if column value is None, otherwise False.
Notes
- The result column will always be of type bool.
Source code in datachain/func/conditional.py
least
Returns the least (smallest) value from the given input values.
Parameters:
-
args
(str | Column | Func | int | float
, default:()
) βThe values to compare. If a string is provided, it is assumed to be the name of the column. If a Column is provided, it is assumed to be a column in the dataset. If a Func is provided, it is assumed to be a function returning a value. If an int or float is provided, it is assumed to be a literal.
Returns:
-
Func
(Func
) βA
Func
object that represents the least function.
Notes
- The result column will always be of the same type as the input columns.
Source code in datachain/func/conditional.py
not_
not_(arg: Union[ColumnElement, Func]) -> Func
Returns the function that produces NOT of the given expressions.
Parameters:
-
arg
(ColumnElement | Func
) βThe expression for NOT statement. If a string is provided, it is assumed to be the name of the column. If a Column is provided, it is assumed to be a column in the dataset. If a Func is provided, it is assumed to be a function returning a value.
Returns:
-
Func
(Func
) βA
Func
object that represents the NOT function.
Notes
- The result column will always be of type bool.
Source code in datachain/func/conditional.py
or_
or_(*args: Union[ColumnElement, Func]) -> Func
Returns the function that produces conjunction of expressions joined by OR logical operator.
Parameters:
-
args
(ColumnElement | Func
, default:()
) βThe expressions for OR statement. If a string is provided, it is assumed to be the name of the column. If a Column is provided, it is assumed to be a column in the dataset. If a Func is provided, it is assumed to be a function returning a value.
Returns:
-
Func
(Func
) βA
Func
object that represents the OR function.
Notes
- The result column will always be of type bool.