Skip to content

Commit

Permalink
docs: add .nullif() example
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews authored and cpcloud committed Oct 5, 2023
1 parent 063cfba commit 6d405df
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ def nullif(self, null_if_expr: Value) -> Value:
Commonly used to avoid divide-by-zero problems by replacing zero with
`NULL` in the divisor.
Equivalent to `(self == null_if_expr).ifelse(ibis.null(), self)`.
Parameters
----------
null_if_expr
Expand All @@ -379,6 +381,36 @@ def nullif(self, null_if_expr: Value) -> Value:
-------
Value
Value expression
Examples
--------
>>> import ibis
>>> ibis.options.interactive = True
>>> vals = ibis.examples.penguins.fetch().head(5).sex
>>> vals
┏━━━━━━━━┓
┃ sex ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ male │
│ female │
│ female │
│ NULL │
│ female │
└────────┘
>>> vals.nullif("male")
┏━━━━━━━━━━━━━━━━━━━━━┓
┃ NullIf(sex, 'male') ┃
┡━━━━━━━━━━━━━━━━━━━━━┩
│ string │
├─────────────────────┤
│ NULL │
│ female │
│ female │
│ NULL │
│ female │
└─────────────────────┘
"""
return ops.NullIf(self, null_if_expr).to_expr()

Expand Down

0 comments on commit 6d405df

Please sign in to comment.