Arrays, maps and structs.
ArrayValue
An Array is a variable-length sequence of values of a single type.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.memtable({"a" : [[1 , None , 3 ], [4 ], [], None ]})
┏━━━━━━━━━━━━━━━━━━━┓
┃ a ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├───────────────────┤
│ [ 1 , None , ... +1 ] │
│ [ 4 ] │
│ [] │
│ NULL │
└───────────────────┘
Methods
alls
Return whether all elements (ignoring nulls) in the array are true.
anys
Return whether any element in the array is true.
concat
Concatenate this array with one or more arrays.
contains
Return whether the array contains other
.
filter
Filter array elements using predicate
function or Deferred
.
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 func
or Deferred
to each element of this array expression.
maxs
Return the maximum value in the array.
means
Return the mean of the values in the array.
mins
Return the minimum value in the array.
remove
Remove other
from self
.
repeat
Repeat this array n
times.
sort
Sort the elements in an array.
sums
Return the sum of the values in the array.
union
Union two arrays.
unique
Return the unique values in an array.
unnest
Unnest an array into a column.
zip
Zip two or more arrays together.
alls
Return whether all elements (ignoring nulls) in the array are true.
Returns NULL if the array is empty or contains only NULLs.
Returns
BooleanValue
Whether all elements (ignoring nulls) in the array are true.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "id" : range (8 ),
... "arr" : [
... [True , False ],
... [False ],
... [True ],
... [None , False ],
... [None , True ],
... [None ],
... [],
... None ,
... ],
... }
... )
>>> t.mutate(x= t.arr.alls()).order_by("id" )
┏━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ id ┃ arr ┃ x ┃
┡━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ int64 │ array<boolean> │ boolean │
├───────┼────────────────┼─────────┤
│ 0 │ [ True , False ] │ False │
│ 1 │ [ False ] │ False │
│ 2 │ [ True ] │ True │
│ 3 │ [ None , False ] │ False │
│ 4 │ [ None , True ] │ True │
│ 5 │ [ None ] │ NULL │
│ 6 │ [] │ NULL │
│ 7 │ NULL │ NULL │
└───────┴────────────────┴─────────┘
anys
Return whether any element in the array is true.
Returns NULL if the array is empty or contains only NULLs.
Returns
BooleanValue
Whether any element in the array is true
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "arr" : [
... [True , False ],
... [False ],
... [True ],
... [None , False ],
... [None , True ],
... [None ],
... [],
... None ,
... ]
... }
... )
>>> t.mutate(x= t.arr.anys())
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ arr ┃ x ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ array<boolean> │ boolean │
├────────────────┼─────────┤
│ [ True , False ] │ True │
│ [ False ] │ False │
│ [ True ] │ True │
│ [ None , False ] │ False │
│ [ None , True ] │ True │
│ [ None ] │ NULL │
│ [] │ NULL │
│ NULL │ NULL │
└────────────────┴─────────┘
concat
Concatenate this array with one or more arrays.
Parameters
other
ArrayValue
Other array to concat with self
required
args
ArrayValue
Other arrays to concat with self
()
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a" : [[7 ], [3 ], None ]})
>>> t
┏━━━━━━━━━━━━━━┓
┃ a ┃
┡━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────┤
│ [ 7 ] │
│ [ 3 ] │
│ NULL │
└──────────────┘
┏━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayConcat((a, a)) ┃
┡━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├─────────────────────┤
│ [ 7 , 7 ] │
│ [ 3 , 3 ] │
│ NULL │
└─────────────────────┘
>>> t.a.concat(ibis.literal([4 ], type = "array<int64>" ))
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayConcat((a, (4,))) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────────┤
│ [ 7 , 4 ] │
│ [ 3 , 4 ] │
│ NULL │
└────────────────────────┘
concat
is also available using the +
operator
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayConcat(((1,), a)) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────────┤
│ [ 1 , 7 ] │
│ [ 1 , 3 ] │
│ NULL │
└────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayConcat((a, (1,))) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────────┤
│ [ 7 , 1 ] │
│ [ 3 , 1 ] │
│ NULL │
└────────────────────────┘
contains
Return whether the array contains other
.
Parameters
other
ir
.Value
Ibis expression to check for existence of in self
required
Returns
BooleanValue
Whether other
is contained in self
Examples
>>> 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 │
└────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayContains(arr, None) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├──────────────────────────┤
│ NULL │
│ NULL │
│ NULL │
│ NULL │
└──────────────────────────┘
filter
Filter array elements using predicate
function or Deferred
.
Parameters
predicate
Deferred | Callable [[ir
.Value
], bool | ir
.BooleanValue
] | Callable [[ir
.Value
, ir
.IntegerValue
], bool | ir
.BooleanValue
]
Function or Deferred
to use to filter array elements. Callables must accept one or two arguments. If there are two arguments, the second argument is the zero -based index of each element of the array.
required
Returns
ArrayValue
Array elements filtered using predicate
Examples
>>> import ibis
>>> from ibis import _
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a" : [[1 , None , 2 ], [4 ], []]})
>>> t
┏━━━━━━━━━━━━━━━━━━━┓
┃ a ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├───────────────────┤
│ [ 1 , None , ... +1 ] │
│ [ 4 ] │
│ [] │
└───────────────────┘
The most succinct way to use filter
is with Deferred
expressions:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayFilter(a, Greater(_, 1), _) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────────────────────────┤
│ [ 2 ] │
│ [ 4 ] │
│ [] │
└──────────────────────────────────┘
You can also use filter
with a lambda function:
>>> t.a.filter (lambda x: x > 1 )
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayFilter(a, Greater(x, 1), x) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────────────────────────┤
│ [ 2 ] │
│ [ 4 ] │
│ [] │
└──────────────────────────────────┘
.filter()
also supports more complex callables like functools.partial
and lambda
s 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), x) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────────────────────────┤
│ [ 2 ] │
│ [ 4 ] │
│ [] │
└──────────────────────────────────┘
>>> y = 1
>>> t.a.filter (lambda x: x > y)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayFilter(a, Greater(x, 1), x) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────────────────────────┤
│ [ 2 ] │
│ [ 4 ] │
│ [] │
└──────────────────────────────────┘
You can optionally include a second index argument in the predicate function
>>> t.a.filter (lambda x, i: i % 4 == 0 )
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayFilter(a, Equals(Modulus(i, 4), 0), x, i) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────────────────────────────────┤
│ [ 1 ] │
│ [ 4 ] │
│ [] │
└────────────────────────────────────────────────┘
flatten
Remove one level of nesting from an array expression.
Examples
>>> 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' ] │
└─────────────────────┘
>>> t.nulls_only.flatten()
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayFlatten(nulls_only) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<struct<a: array<s… │
├──────────────────────────┤
│ NULL │
│ NULL │
│ NULL │
└──────────────────────────┘
>>> t.mixed_nulls.flatten()
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayFlatten(mixed_nulls) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<string> │
├───────────────────────────┤
│ [] │
│ NULL │
│ [] │
└───────────────────────────┘
>>> t.select(s.across(s.all (), _.flatten()))
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ empty ┃ happy ┃ nulls_only ┃ mixed_nulls ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ array<int64> │ array<string> │ array<str… │ array<string> │
├──────────────┼───────────────┼────────────┼───────────────┤
│ [] │ [ 'abc' ] │ NULL │ [] │
│ [] │ [ 'bcd' ] │ NULL │ NULL │
│ [] │ [ 'def' ] │ NULL │ [] │
└──────────────┴───────────────┴────────────┴───────────────┘
index
Return the position of other
in an array.
Parameters
other
ir
.Value
Ibis expression to existence of in self
required
Returns
BooleanValue
The position of other
in self
Examples
>>> 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 │
└─────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayPosition(arr, None) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ int64 │
├──────────────────────────┤
│ NULL │
│ NULL │
│ NULL │
│ NULL │
└──────────────────────────┘
intersect
Intersect two arrays.
Parameters
other
ArrayValue
Another array to intersect with self
required
Examples
>>> 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 ] │
└──────────────┴──────────────┘
>>> t.arr1.intersect(t.arr2)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayIntersect(arr1, arr2) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────────────┤
│ [ 3 ] │
│ [] │
│ NULL │
└────────────────────────────┘
join
Join the elements of this array expression with sep
.
Parameters
sep
str | ir
.StringValue
Separator to use for joining array elements
required
Returns
StringValue
Elements of self
joined with sep
Examples
>>> 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 ] │
└────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayStringJoin(arr, '|') ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ string │
├───────────────────────────┤
│ a|b|c │
│ NULL │
│ NULL │
│ b │
└───────────────────────────┘
length
Compute the length of an array.
Returns
IntegerValue
The integer length of each element of self
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a" : [[7 , 42 ], [3 ], None ]})
>>> t
┏━━━━━━━━━━━━━━┓
┃ a ┃
┡━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────┤
│ [ 7 , 42 ] │
│ [ 3 ] │
│ NULL │
└──────────────┘
┏━━━━━━━━━━━━━━━━┓
┃ ArrayLength(a) ┃
┡━━━━━━━━━━━━━━━━┩
│ int64 │
├────────────────┤
│ 2 │
│ 1 │
│ NULL │
└────────────────┘
map
Apply a func
or Deferred
to each element of this array expression.
Parameters
func
Deferred | Callable [[ir
.Value
], ir
.Value
] | Callable [[ir
.Value
, ir
.Value
], ir
.Value
]
Function or Deferred
to apply to each element of this array. Callables must accept one or two arguments. If there are two arguments, the second argument is the zero -based index of each element of the array.
required
Returns
ArrayValue
func
applied to every element of this array expression.
Examples
>>> import ibis
>>> from ibis import _
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a" : [[1 , None , 2 ], [4 ], []]})
>>> t
┏━━━━━━━━━━━━━━━━━━━┓
┃ a ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├───────────────────┤
│ [ 1 , None , ... +1 ] │
│ [ 4 ] │
│ [] │
└───────────────────┘
The most succinct way to use map
is with Deferred
expressions:
>>> t.a.map ((_ + 100 ).cast("float" ))
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayMap(a, Cast(Add(_, 100), float64), _) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<float64> │
├────────────────────────────────────────────┤
│ [ 101.0 , None , ... +1 ] │
│ [ 104.0 ] │
│ [] │
└────────────────────────────────────────────┘
You can also use map
with a lambda function:
>>> t.a.map (lambda x: (x + 100 ).cast("float" ))
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayMap(a, Cast(Add(x, 100), float64), x) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<float64> │
├────────────────────────────────────────────┤
│ [ 101.0 , None , ... +1 ] │
│ [ 104.0 ] │
│ [] │
└────────────────────────────────────────────┘
.map()
also supports more complex callables like functools.partial
and lambda
s 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), x) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├───────────────────────────┤
│ [ 3 , None , ... +1 ] │
│ [ 6 ] │
│ [] │
└───────────────────────────┘
>>> y = 2
>>> t.a.map (lambda x: x + y)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayMap(a, Add(x, 2), x) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├───────────────────────────┤
│ [ 3 , None , ... +1 ] │
│ [ 6 ] │
│ [] │
└───────────────────────────┘
You can optionally include a second index argument in the mapped function
>>> t.a.map (lambda x, i: i % 2 )
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayMap(a, Modulus(i, 2), x, i) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────────────────────────┤
│ [ 0 , 1 , ... +1 ] │
│ [ 0 ] │
│ [] │
└──────────────────────────────────┘
maxs
Return the maximum value in the array.
Returns NULL if the array is empty or contains only NULLs.
Returns
Value
Maximum value in the array
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[1 , 2 , 3 ], [None , 6 ], [None ], [], None ]})
>>> t.mutate(x= t.arr.maxs())
┏━━━━━━━━━━━━━━━━┳━━━━━━━┓
┃ arr ┃ x ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━┩
│ array<int64> │ int64 │
├────────────────┼───────┤
│ [ 1 , 2 , ... +1 ] │ 3 │
│ [ None , 6 ] │ 6 │
│ [ None ] │ NULL │
│ [] │ NULL │
│ NULL │ NULL │
└────────────────┴───────┘
means
Return the mean of the values in the array.
Returns NULL if the array is empty or contains only NULLs.
Returns
Value
Mean of the values in the array
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[1 , 2 , 3 ], [None , 6 ], [None ], [], None ]})
>>> t.mutate(x= t.arr.means())
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ arr ┃ x ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ array<int64> │ float64 │
├────────────────┼─────────┤
│ [ 1 , 2 , ... +1 ] │ 2.0 │
│ [ None , 6 ] │ 6.0 │
│ [ None ] │ NULL │
│ [] │ NULL │
│ NULL │ NULL │
└────────────────┴─────────┘
mins
Return the minimum value in the array.
Returns NULL if the array is empty or contains only NULLs.
Returns
Value
Minimum value in the array
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[1 , 2 , 3 ], [None , 6 ], [None ], [], None ]})
>>> t.mutate(x= t.arr.mins())
┏━━━━━━━━━━━━━━━━┳━━━━━━━┓
┃ arr ┃ x ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━┩
│ array<int64> │ int64 │
├────────────────┼───────┤
│ [ 1 , 2 , ... +1 ] │ 1 │
│ [ None , 6 ] │ 6 │
│ [ None ] │ NULL │
│ [] │ NULL │
│ NULL │ NULL │
└────────────────┴───────┘
remove
Remove other
from self
.
Parameters
other
ir
.Value
Element to remove from self
.
required
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[3 , 2 ], [], [42 , 2 ], [2 , 2 ], None ]})
>>> t
┏━━━━━━━━━━━━━━┓
┃ arr ┃
┡━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────┤
│ [ 3 , 2 ] │
│ [] │
│ [ 42 , 2 ] │
│ [ 2 , 2 ] │
│ NULL │
└──────────────┘
┏━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayRemove(arr, 2) ┃
┡━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├─────────────────────┤
│ [ 3 ] │
│ [] │
│ [ 42 ] │
│ [] │
│ NULL │
└─────────────────────┘
repeat
Repeat this array n
times.
Parameters
n
int | ir
.IntegerValue
Number of times to repeat self
.
required
Examples
>>> 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
┏━━━━━━━━━━━━━━━━━━━┓
┃ ArrayRepeat(a, 2) ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├───────────────────┤
│ [ 7 , 7 ] │
│ [ 3 , 3 ] │
│ [] │
└───────────────────┘
sort
Sort the elements in an array.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[3 , 2 ], [], [42 , 42 ], None ]})
>>> t
┏━━━━━━━━━━━━━━┓
┃ arr ┃
┡━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────┤
│ [ 3 , 2 ] │
│ [] │
│ [ 42 , 42 ] │
│ NULL │
└──────────────┘
┏━━━━━━━━━━━━━━━━┓
┃ ArraySort(arr) ┃
┡━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────┤
│ [ 2 , 3 ] │
│ [] │
│ [ 42 , 42 ] │
│ NULL │
└────────────────┘
sums
Return the sum of the values in the array.
Returns NULL if the array is empty or contains only NULLs.
Returns
Value
Sum of the values in the array
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[1 , 2 , 3 ], [None , 6 ], [None ], [], None ]})
>>> t.mutate(x= t.arr.sums())
┏━━━━━━━━━━━━━━━━┳━━━━━━━┓
┃ arr ┃ x ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━┩
│ array<int64> │ int64 │
├────────────────┼───────┤
│ [ 1 , 2 , ... +1 ] │ 6 │
│ [ None , 6 ] │ 6 │
│ [ None ] │ NULL │
│ [] │ NULL │
│ NULL │ NULL │
└────────────────┴───────┘
union
Union two arrays.
Parameters
other
ir
.ArrayValue
Another array to union with self
required
Examples
>>> 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 ] │
└────────────────────────┘
>>> t.arr1.union(t.arr2).contains(3 )
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayContains(ArrayUnion(arr1, arr2), 3) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├──────────────────────────────────────────┤
│ True │
│ False │
│ False │
└──────────────────────────────────────────┘
unique
Return the unique values in an array.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"arr" : [[1 , 3 , 3 ], [], [42 , 42 , None ], None ]})
>>> t.arr.unique()
┏━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayDistinct(arr) ┃
┡━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────┤
│ [ 3 , 1 ] │
│ [] │
│ [ 42 , None ] │
│ NULL │
└────────────────────┘
unnest
Unnest an array into a column.
To preserve empty arrays as NULL
s as well as existing NULL
values, use Table.unnest
.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"a" : [[7 , 42 ], [3 , 3 ], None ]})
>>> t
┏━━━━━━━━━━━━━━┓
┃ a ┃
┡━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────┤
│ [ 7 , 42 ] │
│ [ 3 , 3 ] │
│ NULL │
└──────────────┘
┏━━━━━━━┓
┃ a ┃
┡━━━━━━━┩
│ int64 │
├───────┤
│ 7 │
│ 42 │
│ 3 │
│ 3 │
└───────┘
zip
Zip two or more arrays together.
Parameters
other
ArrayValue
Another array to zip with self
required
others
ArrayValue
Additional arrays to zip with self
()
Returns
Array
Array of structs where each struct field is an element of each input array. The fields are named f1
, f2
, f3
, etc.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.options.repr .interactive.max_depth = 2
>>> t = ibis.memtable(
... {
... "numbers" : [[3 , 2 ], [6 , 7 ], [], None ],
... "strings" : [["a" , "c" ], ["d" ], [], ["x" , "y" ]],
... }
... )
>>> t
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ numbers ┃ strings ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ array<int64> │ array<string> │
├──────────────┼───────────────┤
│ [ 3 , 2 ] │ [ 'a' , 'c' ] │
│ [ 6 , 7 ] │ [ 'd' ] │
│ [] │ [] │
│ NULL │ [ 'x' , 'y' ] │
└──────────────┴───────────────┘
>>> t.numbers.zip (t.strings)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ArrayZip((numbers, strings)) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<struct<f1: int64, f2: string>> │
├───────────────────────────────────────────────┤
│ [{ 'f1' : 3 , 'f2' : 'a' } , { 'f1' : 2 , 'f2' : 'c' }] │
│ [{ 'f1' : 6 , 'f2' : 'd' } , { 'f1' : 7 , 'f2' : None }] │
│ [] │
│ NULL │
└───────────────────────────────────────────────┘
MapValue
A dict-like collection with fixed-type keys and values.
Maps are similar to a Python dictionary, with the restriction that all keys must have the same type, and all values must have the same type.
The key type and the value type can be different.
For example, keys are string
s, and values are int64
s.
Keys are unique within a given map value.
Maps can be constructed with ibis.map()
.
Examples
>>> 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
:
┏━━━━━━━━━━━━━━━━━━━┓
┃ MapGet(m, 'b', 0) ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ int64 │
├───────────────────┤
│ 2 │
│ 0 │
│ NULL │
└───────────────────┘
Methods
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
Return whether the map contains key
.
Parameters
key
int | str | ir
.IntegerValue
| ir
.StringValue
Mapping key for which to check
required
Returns
BooleanValue
Boolean indicating the presence of key
in the map expression
Examples
>>> 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 │
└─────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━┓
┃ MapContains(m, 'b') ┃
┡━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├─────────────────────┤
│ True │
│ False │
│ NULL │
└─────────────────────┘
get
Return the value for key
from expr
.
Return default
if key
is not in the map.
Parameters
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
Returns
Value
The element type of self
Examples
>>> 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 │
└──────────────────────┘
┏━━━━━━━━━━━━━━━━━━━┓
┃ MapGet(m, 'b', 0) ┃
┡━━━━━━━━━━━━━━━━━━━┩
│ int64 │
├───────────────────┤
│ 2 │
│ 0 │
│ NULL │
└───────────────────┘
keys
Extract the keys of a map.
Examples
>>> 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 │
└─────────────────────┘
┏━━━━━━━━━━━━━━━━┓
┃ MapKeys(m) ┃
┡━━━━━━━━━━━━━━━━┩
│ array<!string> │
├────────────────┤
│ [ 'a' , 'b' ] │
│ [ 'a' ] │
│ NULL │
└────────────────┘
length
Return the number of key-value pairs in the map.
Returns
IntegerValue
The number of elements in self
Examples
>>> 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 │
└─────────────────────┘
┏━━━━━━━━━━━━━━┓
┃ MapLength(m) ┃
┡━━━━━━━━━━━━━━┩
│ int64 │
├──────────────┤
│ 2 │
│ 1 │
│ NULL │
└──────────────┘
values
Extract the values of a map.
Examples
>>> import ibis
>>> ibis.options.interactive = True
>>> m = ibis.map ({"a" : 1 , "b" : 2 })
>>> m.values()
┌────────┐
│ [ 1 , 2 ] │
└────────┘
StructValue
A Struct is a nested type with ordered fields of any type.
For example, a Struct might have a field a
of type int64
and a field b
of type string
.
Structs can be constructed with ibis.struct()
.
Examples
Construct a Struct
column with fields a: int64
and b: string
>>> 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 │
└─────────────────────────────┘
You can use dot notation (.
) or square-bracket syntax ([]
) to access struct column fields
┏━━━━━━━┓
┃ a ┃
┡━━━━━━━┩
│ int64 │
├───────┤
│ 1 │
│ 3 │
│ NULL │
└───────┘
┏━━━━━━━┓
┃ a ┃
┡━━━━━━━┩
│ int64 │
├───────┤
│ 1 │
│ 3 │
│ NULL │
└───────┘
Attributes
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.
Methods
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.
Returns
list [AnyValue
]
Value expressions corresponding to the struct fields.
Examples
>>> 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, b = t.s.destructure()
>>> a
┏━━━━━━━┓
┃ a ┃
┡━━━━━━━┩
│ int64 │
├───────┤
│ 1 │
│ 3 │
│ NULL │
└───────┘
┏━━━━━━━━┓
┃ b ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ foo │
│ NULL │
│ 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.
Returns
Table
A projection with this struct expression’s fields.
Examples
>>> 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 } │
└────────────────────────────────────┘
┏━━━━━━━━━┳━━━━━━━━━┓
┃ lat ┃ lon ┃
┡━━━━━━━━━╇━━━━━━━━━┩
│ float64 │ float64 │
├─────────┼─────────┤
│ 10.1 │ 30.3 │
│ 10.2 │ 30.2 │
│ 10.3 │ 30.1 │
└─────────┴─────────┘
array
Create an array expression.
If any values are column expressions the result will be a column. Otherwise the result will be a scalar .
Parameters
values
Iterable [V
]
An iterable of Ibis expressions or Python literals
required
Examples
Create an array scalar from scalar values
>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.array([1.0 , None ])
┌─────────────┐
│ [ 1.0 , None ] │
└─────────────┘
Create an array from column and scalar expressions
>>> t = ibis.memtable({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
>>> ibis.array([t.a, 42 , ibis.literal(None )])
┏━━━━━━━━━━━━━━━━━━━━━━┓
┃ Array((a, 42, None)) ┃
┡━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├──────────────────────┤
│ [ 1 , 42 , ... +1 ] │
│ [ 2 , 42 , ... +1 ] │
│ [ 3 , 42 , ... +1 ] │
└──────────────────────┘
>>> ibis.array([t.a, 42 + ibis.literal(5 )])
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Array((a, Add(5, 42))) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━┩
│ array<int64> │
├────────────────────────┤
│ [ 1 , 47 ] │
│ [ 2 , 47 ] │
│ [ 3 , 47 ] │
└────────────────────────┘
map
ibis.map (keys, values= None )
Create a MapValue.
If any of the keys
or values
are Columns, then the output will be a MapColumn. Otherwise, the output will be a MapScalar.
Returns
MapValue
Either a MapScalar or MapColumn, depending on the input shapes.
Examples
Create a Map scalar from a dict with the type inferred
>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.map (dict (a= 1 , b= 2 ))
┌──────────────────┐
│ { 'a' : 1 , 'b' : 2 } │
└──────────────────┘
Create a Map Column from columns with keys and values
>>> 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.map (t.keys, t.values)
┏━━━━━━━━━━━━━━━━━━━━┓
┃ Map(keys, values) ┃
┡━━━━━━━━━━━━━━━━━━━━┩
│ map<string, int64> │
├────────────────────┤
│ { 'a' : 1 , 'b' : 2 } │
│ { 'b' : 3 } │
└────────────────────┘
struct
ibis.struct(value, type = None )
Create a struct expression.
If any of the inputs are Columns, then the output will be a StructColumn
. Otherwise, the output will be a StructScalar
.
Parameters
value
Iterable [tuple [str , V
]] | Mapping [str , V
]
Either a {str: Value}
mapping, or an iterable of tuples of the form (str, Value)
.
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 Python literals. eg struct<a: float, b: string>
.
None
Returns
StructValue
An StructScalar or StructColumn expression.
Examples
Create a struct scalar literal from a dict
with the type inferred
>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.struct(dict (a= 1 , b= "foo" ))
┌──────────────────────┐
│ { 'a' : 1 , 'b' : 'foo' } │
└──────────────────────┘
Specify a type (note the 1 is now a float
):
>>> ibis.struct(dict (a= 1 , b= "foo" ), type = "struct<a: float, b: string>" )
┌────────────────────────┐
│ { 'a' : 1.0 , 'b' : 'foo' } │
└────────────────────────┘
Create a struct column from a column and a scalar literal
>>> t = ibis.memtable({"a" : [1 , 2 , 3 ]})
>>> ibis.struct([("a" , t.a), ("b" , "foo" )])
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ StructColumn({'a': a, 'b': 'foo'}) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ struct<a: int64, b: string> │
├────────────────────────────────────┤
│ { 'a' : 1 , 'b' : 'foo' } │
│ { 'a' : 2 , 'b' : 'foo' } │
│ { 'a' : 3 , 'b' : 'foo' } │
└────────────────────────────────────┘
Back to top