CaseBuilder
- class hail.expr.builders.CaseBuilder[source]
Class for chaining multiple if-else statements.
Examples
>>> x = hl.literal('foo bar baz') >>> expr = (hl.case() ... .when(x[:3] == 'FOO', 1) ... .when(x.length() == 11, 2) ... .when(x == 'secret phrase', 3) ... .default(0)) >>> hl.eval(expr) 2
Notes
All expressions appearing as the then parameters to
when()
ordefault()
method calls must be the same type.- Parameters:
missing_false (
bool
) – Treat missing predicates asFalse
.
Attributes
Methods
Finish the case statement by adding a default case.
Finish the case statement by throwing an error with the given message.
Finish the case statement by returning missing.
Add a branch.
- default(then)[source]
Finish the case statement by adding a default case.
Notes
If no condition from a
when()
call isTrue
, then then is returned.- Parameters:
then (
Expression
)- Returns:
- or_error(message)[source]
Finish the case statement by throwing an error with the given message.
Notes
If no condition from a
CaseBuilder.when()
call isTrue
, then an error is thrown.- Parameters:
message (
Expression
of typetstr
)- Returns:
- or_missing()[source]
Finish the case statement by returning missing.
Notes
If no condition from a
CaseBuilder.when()
call isTrue
, then the result is missing.- Parameters:
then (
Expression
)- Returns:
- when(condition, then)[source]
Add a branch. If condition is
True
, then returns then.Warning
Missingness is treated similarly to
cond()
. Missingness is not treated asFalse
. A condition that evaluates to missing will return a missing result, not proceed to the next case. Always test missingness first in aCaseBuilder
.- Parameters:
condition (
BooleanExpression
)then (
Expression
)
- Returns:
CaseBuilder
– Mutates and returns self.