Skip to content

Commit

Permalink
fix: add workaround for NULL map bugs
Browse files Browse the repository at this point in the history
partially addresses #8632
  • Loading branch information
NickCrews committed Mar 13, 2024
1 parent 93dbbc2 commit 6925c90
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions ibis/backends/tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
]


@pytest.mark.parametrize(
"kv",
[
param(([1, 2], None), id="null_values"),
param((None, [1, 2]), id="null_keys"),
param((None, None), id="null_both"),
],
)
def test_map_nulls(con, kv):
k, v = kv
k = ibis.literal(k, type="array<int64>")
v = ibis.literal(v, type="array<int64>")
m = ibis.map(k, v)
assert con.execute(m) is None


@pytest.mark.notimpl(["pandas", "dask"])
def test_map_table(backend):
table = backend.map
Expand Down
17 changes: 16 additions & 1 deletion ibis/expr/types/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from public import public

import ibis
import ibis.expr.operations as ops
import ibis.expr.types as ir
from ibis.common.deferred import deferrable
from ibis.expr import datatypes as dt
from ibis.expr.types.generic import Column, Scalar, Value

if TYPE_CHECKING:
Expand Down Expand Up @@ -488,4 +490,17 @@ def map(
return keys
if values is None:
keys, values = tuple(keys.keys()), tuple(keys.values())
return ops.Map(keys, values).to_expr()

# workaround for https://github.com/ibis-project/ibis/issues/8632
key_array = ibis.array(keys)
value_array = ibis.array(values)
regular = ops.Map(key_array, value_array).to_expr()
either_null = key_array.isnull() | value_array.isnull()
null = ibis.literal(
None,
type=dt.Map(
key_type=key_array.type().value_type,
value_type=value_array.type().value_type,
),
)
return either_null.ifelse(null, regular)

0 comments on commit 6925c90

Please sign in to comment.