Skip to content

Commit d6cfbad

Browse files
committed
feat(types): add typing overloads to common .cast() dtypes
1 parent a720e68 commit d6cfbad

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

ibis/expr/types/generic.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Sequence
4-
from typing import TYPE_CHECKING, Any
4+
from typing import TYPE_CHECKING, Any, Literal, overload
55

66
from public import public
77

@@ -17,6 +17,9 @@
1717
from ibis.util import deprecated, promote_list
1818

1919
if TYPE_CHECKING:
20+
import datetime
21+
import uuid
22+
2023
import pandas as pd
2124
import polars as pl
2225
import pyarrow as pa
@@ -135,6 +138,48 @@ def hash(self) -> ir.IntegerValue:
135138
"""
136139
return ops.Hash(self).to_expr()
137140

141+
@overload
142+
def cast(
143+
self, target_type: Literal["string", "str"] | type[str]
144+
) -> ir.StringValue: ...
145+
@overload
146+
def cast(
147+
self,
148+
target_type: Literal[
149+
"int",
150+
"uint",
151+
"int8",
152+
"uint8",
153+
"int16",
154+
"uint16",
155+
"int32",
156+
"uint32",
157+
"int64",
158+
"uint64",
159+
]
160+
| type[int],
161+
) -> ir.IntegerValue: ...
162+
@overload
163+
def cast(
164+
self,
165+
target_type: Literal["float", "float8", "float16", "float32", "float64"]
166+
| type[float],
167+
) -> ir.FloatingValue: ...
168+
@overload
169+
def cast(
170+
self, target_type: Literal["bool", "boolean"] | type[bool]
171+
) -> ir.BooleanValue: ...
172+
@overload
173+
def cast(self, target_type: Literal["date"]) -> ir.DateValue: ...
174+
@overload
175+
def cast(
176+
self, target_type: Literal["datetime", "timestamp"] | type[datetime.datetime]
177+
) -> ir.TimestampValue: ...
178+
@overload
179+
def cast(self, target_type: Literal["time"]) -> ir.TimeValue: ...
180+
@overload
181+
def cast(self, target_type: Literal["uuid"] | type[uuid.UUID]) -> ir.UUIDValue: ...
182+
138183
def cast(self, target_type: Any) -> Value:
139184
"""Cast expression to indicated data type.
140185

0 commit comments

Comments
 (0)