Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pyspark): ensure that the output of zip matches the expected ibis schema #9052

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibis/backends/pyspark/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
return self.if_(self.f.map_contains_key(arg, key), arg[key], default)

def visit_ArrayZip(self, op, *, arg):
return self.f.arrays_zip(*arg)
return self.cast(self.f.arrays_zip(*arg), op.dtype)

Check warning on line 352 in ibis/backends/pyspark/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/compiler.py#L352

Added line #L352 was not covered by tests

def visit_ArrayMap(self, op, *, arg, body, param):
param = sge.Identifier(this=param)
Expand Down
20 changes: 20 additions & 0 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,3 +1401,23 @@ def test_array_literal_with_exprs(con, input, expected):
assert expr.op().shape == ds.scalar
result = list(con.execute(expr))
assert result == expected


@pytest.mark.notimpl(
["datafusion", "postgres", "pandas", "polars", "risingwave", "dask", "flink"],
raises=com.OperationNotDefinedError,
)
@pytest.mark.broken(
["trino"],
raises=TrinoUserError,
reason="sqlglot generates code that assumes there's only at most two fields to unpack from a struct",
)
def test_zip_unnest_lift(con):
data = pd.DataFrame(dict(array1=[[1, 2, 3]], array2=[[4, 5, 6]]))
t = ibis.memtable(data)
zipped = t.mutate(zipped=t.array1.zip(t.array2))
unnested = zipped.mutate(unnest=zipped.zipped.unnest())
lifted = unnested.unnest.lift()
result = con.execute(lifted)
expected = pd.DataFrame({"f1": [1, 2, 3], "f2": [4, 5, 6]})
tm.assert_frame_equal(result, expected)
Loading