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

feat(api): support Deferreds in Array.map and .filter #8267

Merged
merged 4 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
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
Next Next commit
test: parameterize test_array_map/filter more
This is in prep for adding in Deferreds
NickCrews authored and cpcloud committed Feb 8, 2024
commit 65f5c2a96edd12070a1339e7e1ac805f9df7e852
38 changes: 22 additions & 16 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
@@ -448,23 +448,26 @@ def test_array_slice(backend, start, stop):
param({"a": [[1, 2], [4]]}, {"a": [[2, 3], [5]]}, id="no_nulls"),
],
)
@pytest.mark.parametrize(
"func",
[
lambda x: x + 1,
functools.partial(lambda x, y: x + y, y=1),
],
)
@pytest.mark.broken(
["risingwave"],
raises=AssertionError,
reason="TODO(Kexiang): seems a bug",
)
def test_array_map(con, input, output):
def test_array_map(con, input, output, func):
t = ibis.memtable(input, schema=ibis.schema(dict(a="!array<int8>")))
t = ibis.memtable(input, schema=ibis.schema(dict(a="!array<int8>")))
expected = pd.Series(output["a"])

expr = t.select(a=t.a.map(lambda x: x + 1))
result = con.execute(expr.a)
assert frozenset(map(tuple, result.values)) == frozenset(
map(tuple, expected.values)
)

expr = t.select(a=t.a.map(functools.partial(lambda x, y: x + y, y=1)))
result = t.a.map(func)
assert result.get_name() == "ArrayMap(a, Add(x, 1))"
expr = t.select(a=result)
result = con.execute(expr.a)
assert frozenset(map(tuple, result.values)) == frozenset(
map(tuple, expected.values)
@@ -512,17 +515,20 @@ def test_array_map(con, input, output):
param({"a": [[1, 2], [4]]}, {"a": [[2], [4]]}, id="no_nulls"),
],
)
def test_array_filter(con, input, output):
@pytest.mark.parametrize(
"predicate",
[
lambda x: x > 1,
functools.partial(lambda x, y: x > y, y=1),
],
)
def test_array_filter(con, input, output, predicate):
t = ibis.memtable(input, schema=ibis.schema(dict(a="!array<int8>")))
expected = pd.Series(output["a"])

expr = t.select(a=t.a.filter(lambda x: x > 1))
result = con.execute(expr.a)
assert frozenset(map(tuple, result.values)) == frozenset(
map(tuple, expected.values)
)

expr = t.select(a=t.a.filter(functools.partial(lambda x, y: x > y, y=1)))
result = t.a.filter(predicate)
assert result.get_name() == "ArrayFilter(a, Greater(x, 1))"
expr = t.select(a=result)
result = con.execute(expr.a)
assert frozenset(map(tuple, result.values)) == frozenset(
map(tuple, expected.values)