Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there an `ANY` or `ANY_VALUE` expression in Ibis that will let me compare a value from a set of values returned by a subquery?

Let t = ibis.memtable({'col0': [-2, -5, -1, 0, 1, 8, 7], 'col1': [0, -2, 4, 5, 6, 8, 7]}).
I want to find all of the rows where col0 is any value in col1.

In SQL, I might do:

SELECT
  *
FROM
  t
WHERE
  col0 = ANY(SELECT col1 FROM t)

(or ANY_VALUE)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a column expression or ibis method for ANY or ANY_VALUE? or a workaround?

I tried looking in the docs but did not come up with an answer.

>Solution :

You can express this kind of computation using our somewhat specialized version of .any() along with view() to make sure that the column you’re comparing against is scanned in full for every value of the search column:

In [17]: from ibis.interactive import *

In [18]: t = ibis.memtable({"a": [1, 2, 3, 4, 5, 6], "b": [3, 4, 5, 6, 1, 2]})

In [19]: t[(t.a > t.view().b).any()]
Out[19]:
┏━━━━━━━┳━━━━━━━┓
┃ a     ┃ b     ┃
┡━━━━━━━╇━━━━━━━┩
│ int64 │ int64 │
├───────┼───────┤
│     5 │     1 │
│     2 │     4 │
│     4 │     6 │
│     3 │     5 │
│     6 │     2 │
└───────┴───────┘
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading