Skip to content

Commit

Permalink
feat(api): support deferred objects in literal
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Aug 22, 2024
1 parent de1595c commit aedb65a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ def null(type: dt.DataType | str | None = None) -> Value:


@public
@deferrable
def literal(value: Any, type: dt.DataType | str | None = None) -> Scalar:
"""Create a scalar expression from a Python value.
Expand Down
9 changes: 9 additions & 0 deletions ibis/tests/expr/test_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import ibis
import ibis.expr.datatypes as dt
from ibis import _
from ibis.common.collections import frozendict
from ibis.expr.operations import Literal
from ibis.tests.util import assert_pickle_roundtrip
Expand Down Expand Up @@ -166,3 +167,11 @@ def test_timestamp_literal_without_tz():
def test_integer_as_decimal():
lit = ibis.literal(12, type="decimal")
assert lit.op().value == decimal.Decimal(12)


def test_deferred(table):
expr = _.g.get_name()
dtype = _.g.type()
deferred = ibis.literal(expr, type=dtype)
result = deferred.resolve(table)
assert result.op().value == "g"
8 changes: 0 additions & 8 deletions ibis/tests/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import hypothesis.strategies as st
import pytest

import ibis
import ibis.expr.datatypes as dt
import ibis.expr.schema as sch
import ibis.expr.types as ir
import ibis.tests.strategies as its
from ibis.common.annotations import ValidationError


@h.given(its.null_dtype)
Expand Down Expand Up @@ -173,10 +171,4 @@ def test_memtable(memtable):
assert isinstance(memtable.schema(), sch.Schema)


@h.given(its.all_dtypes())
def test_deferred_literal(dtype):
with pytest.raises(ValidationError):
ibis.literal(ibis._.a, type=dtype)


# TODO(kszucs): we enforce field name uniqueness in the schema, but we don't for Struct datatype

0 comments on commit aedb65a

Please sign in to comment.