Skip to content

Commit

Permalink
feat(api): add zip operation and api
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed May 17, 2023
1 parent bee1551 commit fecf695
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions ibis/backends/base/sql/alchemy/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sqlalchemy as sa
import sqlalchemy.types as sat
import toolz
from multipledispatch import Dispatcher
from sqlalchemy.dialects import postgresql
from sqlalchemy.engine.default import DefaultDialect
Expand Down
18 changes: 18 additions & 0 deletions ibis/expr/operations/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,21 @@ class ArrayUnion(Value):

output_dtype = rlz.dtype_like("args")
output_shape = rlz.shape_like("args")


@public
class Zip(Value):
arg = rlz.tuple_of(rlz.array, min_length=2)

output_shape = rlz.shape_like("arg")

@attribute.default
def output_dtype(self):
return dt.Array(
dt.Struct(
{
f"f{i:d}": array.output_dtype.value_type
for i, array in enumerate(self.arg, start=1)
}
)
)
18 changes: 18 additions & 0 deletions ibis/expr/types/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,24 @@ def union(self, other: ir.ArrayValue) -> ir.ArrayValue:
"""
return ops.ArrayUnion(self, other).to_expr()

def zip(self, other: ir.Array, *others: ir.Array) -> ir.Array:
"""Zip two or more arrays together.
Parameters
----------
other
Another array to zip with `self`
others
Additional arrays to zip with `self`
Returns
-------
Array
Array of structs where each struct field is an element of each input
array.
"""
return ops.Zip((self, other, *others)).to_expr()


@public
class ArrayScalar(Scalar, ArrayValue):
Expand Down

0 comments on commit fecf695

Please sign in to comment.