selectors
xorq.api.selectors
Convenient column selectors.
Rationale
Column selectors are convenience functions for selecting columns that share some property.
Discussion
For example, a common task is to be able to select all numeric columns for a subsequent computation.
Without selectors this becomes quite verbose and tedious to write:
import ibis t = ibis.table(dict(a=“int”, b=“string”, c=“array
”, abcd=“float”)) expr = t.select([t[c] for c in t.columns if t[c].type().is_numeric()]) expr.columns [‘a’, ‘abcd’]
Compare that to the numeric selector:
import ibis.selectors as s expr = t.select(s.numeric()) expr.columns [‘a’, ‘abcd’]
When there are multiple properties to check it gets worse:
expr = t.select( … [ … t[c] … for c in t.columns … if t[c].type().is_numeric() or t[c].type().is_string() … if (“a” in c or “b” in c or “cd” in c) … ] … ) expr.columns [‘a’, ‘b’, ‘abcd’]
Using a composition of selectors this is much less tiresome:
expr = t.select((s.numeric() | s.of_type(“string”)) & s.contains((“a”, “b”, “cd”))) expr.columns [‘a’, ‘b’, ‘abcd’]