Skip to content

Commit

Permalink
docs: add examples to Value.typeof()
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews authored and cpcloud committed Oct 5, 2023
1 parent 501ae92 commit c146381
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,52 @@ def least(self, *args: ir.Value) -> ir.Value:
return ops.Least((self, *args)).to_expr()

def typeof(self) -> ir.StringValue:
"""Return the data type of the expression.
"""Return the string name of the datatype of self.
The values of the returned strings are necessarily backend dependent.
e.g. duckdb may say "DOUBLE", while sqlite may say "real".
Returns
-------
StringValue
A string indicating the type of the value
Examples
--------
>>> import ibis
>>> ibis.options.interactive = True
>>> vals = ibis.examples.penguins.fetch().head(5).bill_length_mm
>>> vals
┏━━━━━━━━━━━━━━━━┓
┃ bill_length_mm ┃
┡━━━━━━━━━━━━━━━━┩
│ float64 │
├────────────────┤
│ 39.1 │
│ 39.5 │
│ 40.3 │
│ nan │
│ 36.7 │
└────────────────┘
>>> vals.typeof()
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ TypeOf(bill_length_mm) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━┩
│ string │
├────────────────────────┤
│ DOUBLE │
│ DOUBLE │
│ DOUBLE │
│ DOUBLE │
│ DOUBLE │
└────────────────────────┘
Different backends have different names for their native types
>>> ibis.duckdb.connect().execute(ibis.literal(5.4).typeof())
'DOUBLE'
>>> ibis.sqlite.connect().execute(ibis.literal(5.4).typeof())
'real'
"""
return ops.TypeOf(self).to_expr()

Expand Down

0 comments on commit c146381

Please # to comment.