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 e221216
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 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"

0 comments on commit e221216

Please sign in to comment.