>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [[7], [3], None]})
>>> t
┏━━━━━━━━━━━━━━┓ ┃ a ┃ ┡━━━━━━━━━━━━━━┩ │ array<int64> │ ├──────────────┤ │ [7] │ │ [3] │ │ NULL │ └──────────────┘
Arrays, maps and structs.
ArrayValue(self, arg)
Name | Description |
---|---|
concat | Concatenate this array with one or more arrays. |
contains | Return whether the array contains other . |
filter | Filter array elements using predicate . |
flatten | Remove one level of nesting from an array expression. |
index | Return the position of other in an array. |
intersect | Intersect two arrays. |
join | Join the elements of this array expression with sep . |
length | Compute the length of an array. |
map | Apply a callable func to each element of this array expression. |
remove | Remove other from self . |
repeat | Repeat this array n times. |
sort | Sort the elements in an array. |
union | Union two arrays. |
unique | Return the unique values in an array. |
unnest | Flatten an array into a column. |
zip | Zip two or more arrays together. |
concat(other, *args)
Concatenate this array with one or more arrays.
Name | Type | Description | Default |
---|---|---|---|
other |
ArrayValue | Other array to concat with self |
required |
args |
ArrayValue | Other arrays to concat with self |
() |
Type | Description |
---|---|
ArrayValue | self concatenated with other and args |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [[7], [3], None]})
>>> t
┏━━━━━━━━━━━━━━┓ ┃ a ┃ ┡━━━━━━━━━━━━━━┩ │ array<int64> │ ├──────────────┤ │ [7] │ │ [3] │ │ NULL │ └──────────────┘
┏━━━━━━━━━━━━━━━┓ ┃ ArrayConcat() ┃ ┡━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────┤ │ [7, 7] │ │ [3, 3] │ │ NULL │ └───────────────┘
┏━━━━━━━━━━━━━━━┓ ┃ ArrayConcat() ┃ ┡━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────┤ │ [7, 4] │ │ [3, 4] │ │ [4] │ └───────────────┘
concat
is also available using the +
operator
┏━━━━━━━━━━━━━━━┓ ┃ ArrayConcat() ┃ ┡━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────┤ │ [1, 7] │ │ [1, 3] │ │ [1] │ └───────────────┘
contains(other)
Return whether the array contains other
.
Name | Type | Description | Default |
---|---|---|---|
other |
ir .Value |
Ibis expression to check for existence of in self |
required |
Type | Description |
---|---|
BooleanValue |
Whether other is contained in self |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr": [[1], [], [42, 42], None]})
>>> t
┏━━━━━━━━━━━━━━┓ ┃ arr ┃ ┡━━━━━━━━━━━━━━┩ │ array<int64> │ ├──────────────┤ │ [1] │ │ [] │ │ [42, 42] │ │ NULL │ └──────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayContains(arr, 42) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━┩ │ boolean │ ├────────────────────────┤ │ False │ │ False │ │ True │ │ NULL │ └────────────────────────┘
filter(predicate)
Filter array elements using predicate
.
Name | Type | Description | Default |
---|---|---|---|
predicate |
Callable[[ir .Value ], bool | ir .BooleanValue ] |
Function to use to filter array elements | required |
Type | Description |
---|---|
ArrayValue | Array elements filtered using predicate |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [[1, None, 2], [4], []]})
>>> t
┏━━━━━━━━━━━━━━━━━━━┓ ┃ a ┃ ┡━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────────┤ │ [1, None, ... +1] │ │ [4] │ │ [] │ └───────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayFilter(a, Greater(x, 1)) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────────────────────┤ │ [2] │ │ [4] │ │ [] │ └───────────────────────────────┘
.filter()
also supports more complex callables like functools.partial
and lambdas with closures
>>> from functools import partial
>>> def gt(x, y):
... return x > y
>>> gt1 = partial(gt, y=1)
>>> t.a.filter(gt1)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayFilter(a, Greater(x, 1)) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────────────────────┤ │ [2] │ │ [4] │ │ [] │ └───────────────────────────────┘
flatten()
Remove one level of nesting from an array expression.
Type | Description |
---|---|
ArrayValue | Flattened array expression |
>>> import ibis
>>> import ibis.selectors as s
>>> from ibis import _
>>> ibis.options.interactive = True
>>> schema = {
... "empty": "array<array<int>>",
... "happy": "array<array<string>>",
... "nulls_only": "array<array<struct<a: array<string>>>>",
... "mixed_nulls": "array<array<string>>",
... }
>>> data = {
... "empty": [[], [], []],
... "happy": [[["abc"]], [["bcd"]], [["def"]]],
... "nulls_only": [None, None, None],
... "mixed_nulls": [[], None, [None]],
... }
>>> import pyarrow as pa
>>> t = ibis.memtable(
... pa.Table.from_pydict(
... data,
... schema=ibis.schema(schema).to_pyarrow(),
... )
... )
>>> t
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓ ┃ empty ┃ happy ┃ nulls_only ┃ mixed_nulls ┃ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩ │ array<array<int64>> │ array<array<string>> │ array<arr… │ array<array<string>> │ ├─────────────────────┼──────────────────────┼────────────┼──────────────────────┤ │ [] │ [[...]] │ NULL │ [] │ │ [] │ [[...]] │ NULL │ NULL │ │ [] │ [[...]] │ NULL │ [None] │ └─────────────────────┴──────────────────────┴────────────┴──────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayFlatten(empty) ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├─────────────────────┤ │ [] │ │ [] │ │ [] │ └─────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayFlatten(happy) ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ array<string> │ ├─────────────────────┤ │ ['abc'] │ │ ['bcd'] │ │ ['def'] │ └─────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayFlatten(nulls_only) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<struct<a: array<s… │ ├──────────────────────────┤ │ NULL │ │ NULL │ │ NULL │ └──────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayFlatten(mixed_nulls) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<string> │ ├───────────────────────────┤ │ [] │ │ NULL │ │ [] │ └───────────────────────────┘
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ empty ┃ happy ┃ nulls_only ┃ mixed_nulls ┃ ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ array<int64> │ array<string> │ array<str… │ array<string> │ ├──────────────┼───────────────┼────────────┼───────────────┤ │ [] │ ['abc'] │ NULL │ [] │ │ [] │ ['bcd'] │ NULL │ NULL │ │ [] │ ['def'] │ NULL │ [] │ └──────────────┴───────────────┴────────────┴───────────────┘
index(other)
Return the position of other
in an array.
Name | Type | Description | Default |
---|---|---|---|
other |
ir .Value |
Ibis expression to existence of in self |
required |
Type | Description |
---|---|
BooleanValue |
The position of other in self |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr": [[1], [], [42, 42], None]})
>>> t
┏━━━━━━━━━━━━━━┓ ┃ arr ┃ ┡━━━━━━━━━━━━━━┩ │ array<int64> │ ├──────────────┤ │ [1] │ │ [] │ │ [42, 42] │ │ NULL │ └──────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayPosition(arr, 42) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├────────────────────────┤ │ -1 │ │ -1 │ │ 0 │ │ NULL │ └────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayPosition(arr, 800) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├─────────────────────────┤ │ -1 │ │ -1 │ │ -1 │ │ NULL │ └─────────────────────────┘
intersect(other)
Intersect two arrays.
Name | Type | Description | Default |
---|---|---|---|
other |
ArrayValue | Another array to intersect with self |
required |
Type | Description |
---|---|
ArrayValue | Intersected arrays |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr1": [[3, 2], [], None], "arr2": [[1, 3], [None], [5]]})
>>> t
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓ ┃ arr1 ┃ arr2 ┃ ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩ │ array<int64> │ array<int64> │ ├──────────────┼──────────────┤ │ [3, 2] │ [1, 3] │ │ [] │ [None] │ │ NULL │ [5] │ └──────────────┴──────────────┘
join(sep)
Join the elements of this array expression with sep
.
Name | Type | Description | Default |
---|---|---|---|
sep |
str | ir .StringValue |
Separator to use for joining array elements | required |
Type | Description |
---|---|
StringValue |
Elements of self joined with sep |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr": [["a", "b", "c"], None, [], ["b", None]]})
>>> t
┏━━━━━━━━━━━━━━━━━━━━┓ ┃ arr ┃ ┡━━━━━━━━━━━━━━━━━━━━┩ │ array<string> │ ├────────────────────┤ │ ['a', 'b', ... +1] │ │ NULL │ │ [] │ │ ['b', None] │ └────────────────────┘
length()
Compute the length of an array.
Type | Description |
---|---|
IntegerValue |
The integer length of each element of self |
map(func)
Apply a callable func
to each element of this array expression.
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[[ir .Value ], ir .Value ] |
Function to apply to each element of this array | required |
Type | Description |
---|---|
ArrayValue | func applied to every element of this array expression. |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [[1, None, 2], [4], []]})
>>> t
┏━━━━━━━━━━━━━━━━━━━┓ ┃ a ┃ ┡━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────────┤ │ [1, None, ... +1] │ │ [4] │ │ [] │ └───────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayMap(a, Cast(Add(x, 100), float64)) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<float64> │ ├─────────────────────────────────────────┤ │ [101.0, None, ... +1] │ │ [104.0] │ │ [] │ └─────────────────────────────────────────┘
.map()
also supports more complex callables like functools.partial
and lambdas with closures
>>> from functools import partial
>>> def add(x, y):
... return x + y
>>> add2 = partial(add, y=2)
>>> t.a.map(add2)
┏━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayMap(a, Add(x, 2)) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├────────────────────────┤ │ [3, None, ... +1] │ │ [6] │ │ [] │ └────────────────────────┘
remove(other)
Remove other
from self
.
Name | Type | Description | Default |
---|---|---|---|
other |
ir .Value |
Element to remove from self . |
required |
repeat(n)
Repeat this array n
times.
Name | Type | Description | Default |
---|---|---|---|
n |
int | ir .IntegerValue |
Number of times to repeat self . |
required |
Type | Description |
---|---|
ArrayValue | self repeated n times |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [[7], [3], None]})
>>> t
┏━━━━━━━━━━━━━━┓ ┃ a ┃ ┡━━━━━━━━━━━━━━┩ │ array<int64> │ ├──────────────┤ │ [7] │ │ [3] │ │ NULL │ └──────────────┘
┏━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayRepeat(a, 2) ┃ ┡━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├───────────────────┤ │ [7, 7] │ │ [3, 3] │ │ [] │ └───────────────────┘
repeat
is also available using the *
operator
sort()
Sort the elements in an array.
Type | Description |
---|---|
ArrayValue | Sorted values in an array |
union(other)
Union two arrays.
Name | Type | Description | Default |
---|---|---|---|
other |
ir .ArrayValue |
Another array to union with self |
required |
Type | Description |
---|---|
ArrayValue | Unioned arrays |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr1": [[3, 2], [], None], "arr2": [[1, 3], [None], [5]]})
>>> t
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓ ┃ arr1 ┃ arr2 ┃ ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩ │ array<int64> │ array<int64> │ ├──────────────┼──────────────┤ │ [3, 2] │ [1, 3] │ │ [] │ [None] │ │ NULL │ [5] │ └──────────────┴──────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayUnion(arr1, arr2) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<int64> │ ├────────────────────────┤ │ [1, 2, ... +1] │ │ [None] │ │ [5] │ └────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayContains(ArrayUnion(arr1, arr2), 3) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ boolean │ ├──────────────────────────────────────────┤ │ True │ │ False │ │ False │ └──────────────────────────────────────────┘
unique()
Return the unique values in an array.
Type | Description |
---|---|
ArrayValue | Unique values in an array |
unnest()
Flatten an array into a column.
Type | Description |
---|---|
ir .Value |
Unnested array |
zip(other, *others)
Zip two or more arrays together.
Name | Type | Description | Default |
---|---|---|---|
other |
ArrayValue | Another array to zip with self |
required |
others |
ArrayValue | Additional arrays to zip with self |
() |
Type | Description |
---|---|
Array |
Array of structs where each struct field is an element of each input array. |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"numbers": [[3, 2], [], None], "strings": [["a", "c"], None, ["e"]]})
>>> t
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ numbers ┃ strings ┃ ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ array<int64> │ array<string> │ ├──────────────┼───────────────┤ │ [3, 2] │ ['a', 'c'] │ │ [] │ NULL │ │ NULL │ ['e'] │ └──────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ArrayZip() ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ array<struct<f1: int64, f2: string>> │ ├──────────────────────────────────────┤ │ [{...}, {...}] │ │ [] │ │ [{...}] │ └──────────────────────────────────────┘
MapValue(self, arg)
A map literal or column expression.
Can be constructed with ibis.map()
.
>>> import ibis
>>> ibis.options.interactive = True
>>> import pyarrow as pa
>>> tab = pa.table(
... {
... "m": pa.array(
... [[("a", 1), ("b", 2)], [("a", 1)], None],
... type=pa.map_(pa.utf8(), pa.int64()),
... )
... }
... )
>>> t = ibis.memtable(tab)
>>> t
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ m ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ map<!string, int64> │ ├─────────────────────┤ │ {'a': 1, 'b': 2} │ │ {'a': 1} │ │ NULL │ └─────────────────────┘
Can use []
to access values:
┏━━━━━━━━━━━━━━━━━━━━━━┓ ┃ MapGet(m, 'a', None) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├──────────────────────┤ │ 1 │ │ 1 │ │ NULL │ └──────────────────────┘
To provide default values, use get
:
Name | Description |
---|---|
contains | Return whether the map contains key . |
get | Return the value for key from expr . |
keys | Extract the keys of a map. |
length | Return the number of key-value pairs in the map. |
values | Extract the values of a map. |
contains(key)
Return whether the map contains key
.
Name | Type | Description | Default |
---|---|---|---|
key |
int | str | ir .IntegerValue | ir .StringValue |
Mapping key for which to check | required |
Type | Description |
---|---|
BooleanValue |
Boolean indicating the presence of key in the map expression |
>>> import ibis
>>> import pyarrow as pa
>>> ibis.options.interactive = True
>>> tab = pa.table(
... {
... "m": pa.array(
... [[("a", 1), ("b", 2)], [("a", 1)], None],
... type=pa.map_(pa.utf8(), pa.int64()),
... )
... }
... )
>>> t = ibis.memtable(tab)
>>> t
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ m ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ map<!string, int64> │ ├─────────────────────┤ │ {'a': 1, 'b': 2} │ │ {'a': 1} │ │ NULL │ └─────────────────────┘
get(key, default=None)
Return the value for key
from expr
.
Return default
if key
is not in the map.
Name | Type | Description | Default |
---|---|---|---|
key |
ir .Value |
Expression to use for key | required |
default |
ir .Value | None |
Expression to return if key is not a key in expr |
None |
Type | Description |
---|---|
Value | The element type of self |
>>> import ibis
>>> import pyarrow as pa
>>> ibis.options.interactive = True
>>> tab = pa.table(
... {
... "m": pa.array(
... [[("a", 1), ("b", 2)], [("a", 1)], None],
... type=pa.map_(pa.utf8(), pa.int64()),
... )
... }
... )
>>> t = ibis.memtable(tab)
>>> t
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ m ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ map<!string, int64> │ ├─────────────────────┤ │ {'a': 1, 'b': 2} │ │ {'a': 1} │ │ NULL │ └─────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━┓ ┃ MapGet(m, 'a', None) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├──────────────────────┤ │ 1 │ │ 1 │ │ NULL │ └──────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━┓ ┃ MapGet(m, 'b', None) ┃ ┡━━━━━━━━━━━━━━━━━━━━━━┩ │ int64 │ ├──────────────────────┤ │ 2 │ │ NULL │ │ NULL │ └──────────────────────┘
keys()
Extract the keys of a map.
Type | Description |
---|---|
ArrayValue |
The keys of self |
>>> import ibis
>>> import pyarrow as pa
>>> ibis.options.interactive = True
>>> tab = pa.table(
... {
... "m": pa.array(
... [[("a", 1), ("b", 2)], [("a", 1)], None],
... type=pa.map_(pa.utf8(), pa.int64()),
... )
... }
... )
>>> t = ibis.memtable(tab)
>>> t
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ m ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ map<!string, int64> │ ├─────────────────────┤ │ {'a': 1, 'b': 2} │ │ {'a': 1} │ │ NULL │ └─────────────────────┘
length()
Return the number of key-value pairs in the map.
Type | Description |
---|---|
IntegerValue |
The number of elements in self |
>>> import ibis
>>> import pyarrow as pa
>>> ibis.options.interactive = True
>>> tab = pa.table(
... {
... "m": pa.array(
... [[("a", 1), ("b", 2)], [("a", 1)], None],
... type=pa.map_(pa.utf8(), pa.int64()),
... )
... }
... )
>>> t = ibis.memtable(tab)
>>> t
┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ m ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ map<!string, int64> │ ├─────────────────────┤ │ {'a': 1, 'b': 2} │ │ {'a': 1} │ │ NULL │ └─────────────────────┘
values()
Extract the values of a map.
Type | Description |
---|---|
ArrayValue |
The values of self |
StructValue(self, arg)
A struct literal or column.
Can be constructed with ibis.struct()
.
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"s": [{"a": 1, "b": "foo"}, {"a": 3, "b": None}, None]})
>>> t
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ s ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ struct<a: int64, b: string> │ ├─────────────────────────────┤ │ {'a': 1, 'b': 'foo'} │ │ {'a': 3, 'b': None} │ │ NULL │ └─────────────────────────────┘
Can use either .
or []
to access fields:
Name | Description |
---|---|
fields | Return a mapping from field name to field type of the struct. |
names | Return the field names of the struct. |
types | Return the field types of the struct. |
Name | Description |
---|---|
destructure | Destructure a StructValue into the corresponding struct fields. |
lift | Project the fields of self into a table. |
destructure()
Destructure a StructValue
into the corresponding struct fields.
When assigned, a destruct value will be destructured and assigned to multiple columns.
Type | Description |
---|---|
list[AnyValue ] |
Value expressions corresponding to the struct fields. |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"s": [{"a": 1, "b": "foo"}, {"a": 3, "b": None}, None]})
>>> t
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ s ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ struct<a: int64, b: string> │ ├─────────────────────────────┤ │ {'a': 1, 'b': 'foo'} │ │ {'a': 3, 'b': None} │ │ NULL │ └─────────────────────────────┘
┏━━━━━━━┓ ┃ a ┃ ┡━━━━━━━┩ │ int64 │ ├───────┤ │ 1 │ │ 3 │ │ NULL │ └───────┘
lift()
Project the fields of self
into a table.
This method is useful when analyzing data that has deeply nested structs or arrays of structs. lift
can be chained to avoid repeating column names and table references.
Type | Description |
---|---|
Table |
A projection with this struct expression’s fields. |
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "pos": [
... {"lat": 10.1, "lon": 30.3},
... {"lat": 10.2, "lon": 30.2},
... {"lat": 10.3, "lon": 30.1},
... ]
... }
... )
>>> t
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ pos ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ struct<lat: float64, lon: float64> │ ├────────────────────────────────────┤ │ {'lat': 10.1, 'lon': 30.3} │ │ {'lat': 10.2, 'lon': 30.2} │ │ {'lat': 10.3, 'lon': 30.1} │ └────────────────────────────────────┘
ibis.array(values)
Create an array expression.
Name | Type | Description | Default |
---|---|---|---|
values |
Iterable[V ] |
An iterable of Ibis expressions or a list of Python literals | required |
Type | Description |
---|---|
ArrayValue |
Create an array from scalar values
Create an array from column and scalar expressions
ibis.map(keys, values=None)
Create a map container object.
If the keys
and values
are Python literals, then the output will be a MapScalar
. If the keys
and values
are expressions (ArrayColumn
), then the the output will be a MapColumn
.
Name | Type | Description | Default |
---|---|---|---|
keys |
Iterable[Any] | Mapping[Any, Any] | ArrayColumn |
Keys of the map or Mapping . If keys is a Mapping , values must be None . |
required |
values |
Iterable[Any] | ArrayColumn | None |
Values of the map or None . If None , the keys argument must be a Mapping . |
None |
Type | Description |
---|---|
MapValue | An expression representing either a map column or literal (associative array with key/value pairs of fixed types) |
Create a map literal from a dict with the type inferred
Create a new map column from columns with keys and values
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"keys": [["a", "b"], ["b"]], "values": [[1, 2], [3]]})
>>> t
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓ ┃ keys ┃ values ┃ ┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩ │ array<string> │ array<int64> │ ├───────────────┼──────────────┤ │ ['a', 'b'] │ [1, 2] │ │ ['b'] │ [3] │ └───────────────┴──────────────┘
ibis.struct(value, type=None)
Create a struct expression.
If the input expressions are all column expressions, then the output will be a StructColumn
.
If the input expressions are Python literals, then the output will be a StructScalar
.
Name | Type | Description | Default |
---|---|---|---|
value |
Iterable[tuple[str, V ]] | Mapping[str, V ] |
The underlying data for literal struct value or a pairs of field names and column expressions. | required |
type |
str | dt .DataType | None |
An instance of ibis.expr.datatypes.DataType or a string indicating the ibis type of value . This is only used if all of the input values are literals. |
None |
Type | Description |
---|---|
StructValue | An expression representing a literal or column struct (compound type with fields of fixed types) |
Create a struct literal from a dict
with the type inferred
Create a struct literal from a dict
with a specified type
Specify a specific type for the struct literal
Create a struct array from multiple arrays
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a": [1, 2, 3], "b": ["foo", "bar", "baz"]})
>>> ibis.struct([("a", t.a), ("b", t.b)])
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ StructColumn() ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ struct<a: int64, b: string> │ ├─────────────────────────────┤ │ {'a': 1, 'b': 'foo'} │ │ {'a': 2, 'b': 'bar'} │ │ {'a': 3, 'b': 'baz'} │ └─────────────────────────────┘
Create a struct array from columns and literals