Skip to content

Commit

Permalink
fix(polars): add workaround to compile Array<Array> correctly (#9484)
Browse files Browse the repository at this point in the history
Workaround for pola-rs/polars#17294

pl.concat_list(Iterable[T]) results in pl.List[T], EXCEPT when T is a
pl.List, in which case pl.concat_list(Iterable[pl.List[T]]) results in
pl.List[T].
If polars ever supports a more consistent array constructor,
we should switch to that.

Found this when working on
#9473
  • Loading branch information
NickCrews committed Jul 1, 2024
1 parent 87cba01 commit 5a9d026
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 7 additions & 0 deletions ibis/backends/polars/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,13 @@ def array_concat(op, **kw):
@translate.register(ops.Array)
def array_column(op, **kw):
cols = [translate(col, **kw) for col in op.exprs]
# Workaround for https://github.com/pola-rs/polars/issues/17294
# pl.concat_list(Iterable[T]) results in pl.List[T], EXCEPT when T is a
# pl.List, in which case pl.concat_list(Iterable[pl.List[T]]) results in pl.List[T].
# If polars ever supports a more consistent array constructor,
# we should switch to that.
if op.dtype.value_type.is_array():
cols = [c.implode() for c in cols]
return pl.concat_list(cols)


Expand Down
9 changes: 1 addition & 8 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,14 +1352,7 @@ def test_unnest_range(con):
[[1], ibis.literal([2])],
[[1], [2]],
id="array",
marks=[
pytest.mark.notyet(["bigquery"], raises=GoogleBadRequest),
pytest.mark.broken(
["polars"],
reason="expression input not supported with nested arrays",
raises=TypeError,
),
],
marks=[pytest.mark.notyet(["bigquery"], raises=GoogleBadRequest)],
),
],
)
Expand Down

0 comments on commit 5a9d026

Please sign in to comment.