Search code examples
pythonibis

ibis: select map on array value works with table object but not with the underscore operation


for a table with a list field i'm trying to call map

import ibis
from ibis import _
t = ibis.memtable({
    'i': [1,2,3], 
    'x': [[1,2],[3,5],[6,7] ]
  })

using the table object works:

t.select(t.x.map(_ + 1))

but using the underscore api (chain expressions) fails:

t.select(_.x.map(_ + 1))

TypeError: unsupported operand type(s) for +: 'Table' and 'int'


Solution

  • The underscore API in this context would be ambiguous here as to whether it refers to a lambda parameter or the outer table.

    As I say here, there's no real reason to prevent use of the second case in a call to ArrayMap.

    For example:

    t.my_array_col.map(lambda x: _.a + x)
    

    It's not clear how to reliably determine what the underscore means when mixed like in your original example, and we don't want to prevent valid uses of it in the underscore-as-outer-table use, so that's its meaning.