diff --git a/ibis/expr/types/maps.py b/ibis/expr/types/maps.py index e5793c901f9df..9bf7e22fc4c80 100644 --- a/ibis/expr/types/maps.py +++ b/ibis/expr/types/maps.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from collections.abc import Iterable, Mapping - from ibis.expr.types import dt + from ibis.expr import datatypes as dt @public @@ -492,6 +492,8 @@ def map( │ {'b': 3.0} │ └───────────────────────────────────────────────┘ """ + from ibis.expr import datatypes as dt + if keys is None: if type is None: raise TypeError("Must specify a type when keys is None") @@ -502,8 +504,11 @@ def map( else: if values is None: keys, values = tuple(keys.keys()), tuple(keys.values()) - if not isinstance(keys, Value) and len(keys) == 0 and type is None: - raise TypeError("Must specify a type when keys is empty") + type = dt.dtype(type) if type is not None else None + key_type = dt.Array(value_type=type.key_type) if type is not None else None + value_type = dt.Array(value_type=type.value_type) if type is not None else None + keys = ibis.array(keys, type=key_type) + values = ibis.array(values, type=value_type) result = ops.Map(keys, values).to_expr() if type is not None: