Skip to content

Commit 19e7273

Browse files
committed
docs: improve error message when trying to infer the dtype of Deferreds
See #11608 (comment)
1 parent e4e582a commit 19e7273

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ibis/expr/datatypes/value.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
from collections.abc import Mapping, Sequence
1111
from functools import partial
1212
from operator import attrgetter
13-
from typing import Any
13+
from typing import Any, NoReturn
1414

1515
import toolz
1616
from public import public
1717

1818
import ibis.expr.datatypes as dt
1919
from ibis.common.collections import frozendict
20+
from ibis.common.deferred import Deferred
2021
from ibis.common.dispatch import lazy_singledispatch
2122
from ibis.common.exceptions import IbisTypeError, InputTypeError
2223
from ibis.common.numeric import normalize_decimal
@@ -37,6 +38,16 @@ def infer(value: Any) -> dt.DataType:
3738
)
3839

3940

41+
@infer.register(Deferred)
42+
def infer_deferred(value: Deferred) -> NoReturn:
43+
raise TypeError(
44+
"Cannot infer the type of a Deferred value. "
45+
"You will need to use a bound value instead. "
46+
"For example, if you have `ibis._.my_col + 5`, "
47+
"you will need to replace this with `my_table.my_col + 5`."
48+
)
49+
50+
4051
# TODO(kszucs): support NamedTuples and dataclasses instead of OrderedDict
4152
# which should trigger infer_map instead
4253
@infer.register(collections.OrderedDict)

0 commit comments

Comments
 (0)