Skip to content

How can I use a backend's built-in function to create a new column in an Ibis dataframe? #9153

Answered by gforsyth
stereoF asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @stereoF -- you can use a builtin UDF for this:

[ins] In [1]: import ibis

[ins] In [2]: con = ibis.clickhouse.connect()

[ins] In [3]: ibis.options.interactive = True

[ins] In [4]: ibis.set_backend(con)

[ins] In [5]: t = ibis.memtable({"b": ["hey", "yo"]})

[ins] In [6]: t
Out[6]: 
┏━━━━━━━━┓
┃ b      ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ hey    │
│ yo     │
└────────┘

[ins] In [7]: @ibis.udf.scalar.builtin
         ...: def halfMD5(val) -> int: ...

[ins] In [8]: t.mutate(c=halfMD5(t.b))
Out[8]: 
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ bc                   ┃
┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ stringint64               │
├────────┼─────────────────────┤
│ hey69422825918…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cpcloud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants