ibis.expr.api.ValueExpr.case

ValueExpr.case()

Create a new SimpleCaseBuilder to chain multiple if-else statements. Add new search expressions with the .when method. These must be comparable with this array expression. Conclude by calling .end()

Returns:
builder : CaseBuilder

Examples

>>> import ibis
>>> t = ibis.table([('string_col', 'string')], name='t')
>>> expr = t.string_col
>>> case_expr = (expr.case()
...              .when('a', 'an a')
...              .when('b', 'a b')
...              .else_('null or (not a and not b)')
...              .end())
>>> case_expr  
ref_0
UnboundTable[table]
  name: t
  schema:
    string_col : string

SimpleCase[string*]
  base:
    string_col = Column[string*] 'string_col' from table
      ref_0
  cases:
    ValueList[string*]
      Literal[string]
        a
      Literal[string]
        b
  results:
    ValueList[string*]
      Literal[string]
        an a
      Literal[string]
        a b
  default:
    Literal[string]
      null or (not a and not b)