Skip to content

Commit 0482d15

Browse files
committed
fix(polars): remove non-working Binary and Decimal literal inference
1 parent b219919 commit 0482d15

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

ibis/backends/polars/compiler.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,26 @@ def _make_duration(value, dtype):
7272

7373
@translate.register(ops.Literal)
7474
def literal(op):
75-
if op.dtype.is_array():
76-
value = pl.Series("", op.value)
77-
typ = to_polars_type(op.dtype)
75+
value = op.value
76+
dtype = op.dtype
77+
78+
if dtype.is_array():
79+
value = pl.Series("", value)
80+
typ = to_polars_type(dtype)
7881
return pl.lit(value, dtype=typ).list()
79-
elif op.dtype.is_struct():
82+
elif dtype.is_struct():
8083
values = [
81-
pl.lit(v, dtype=to_polars_type(op.dtype[k])).alias(k)
82-
for k, v in op.value.items()
84+
pl.lit(v, dtype=to_polars_type(dtype[k])).alias(k) for k, v in value.items()
8385
]
8486
return pl.struct(values)
85-
elif op.dtype.is_interval():
86-
return _make_duration(op.value, op.dtype)
87-
elif op.dtype.is_null():
88-
return pl.lit(op.value)
87+
elif dtype.is_interval():
88+
return _make_duration(value, dtype)
89+
elif dtype.is_null():
90+
return pl.lit(value)
91+
elif dtype.is_binary():
92+
raise NotImplementedError("Binary literals do not work in polars")
8993
else:
90-
typ = to_polars_type(op.dtype)
94+
typ = to_polars_type(dtype)
9195
return pl.lit(op.value, dtype=typ)
9296

9397

ibis/backends/polars/datatypes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
dt.Null: pl.Null,
1313
dt.Array: pl.List,
1414
dt.String: pl.Utf8,
15-
dt.Binary: pl.Object,
15+
dt.Binary: pl.Binary,
1616
dt.Date: pl.Date,
1717
dt.Time: pl.Time,
1818
dt.Int8: pl.Int8,
@@ -25,7 +25,6 @@
2525
dt.UInt64: pl.UInt64,
2626
dt.Float32: pl.Float32,
2727
dt.Float64: pl.Float64,
28-
dt.Decimal: pl.Object,
2928
}
3029

3130
_to_ibis_dtypes = {v: k for k, v in _to_polars_types.items()}
@@ -34,7 +33,12 @@
3433
@functools.singledispatch
3534
def to_polars_type(dtype):
3635
"""Convert ibis dtype to the polars counterpart."""
37-
return _to_polars_types[dtype.__class__] # else return pl.Object?
36+
try:
37+
return _to_polars_types[dtype.__class__] # else return pl.Object?
38+
except KeyError:
39+
raise NotImplementedError(
40+
f"Translation to polars dtype not implemented for {dtype}"
41+
)
3842

3943

4044
@to_polars_type.register(dt.Timestamp)

0 commit comments

Comments
 (0)