|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | from collections.abc import Sequence
|
4 |
| -from typing import TYPE_CHECKING, Any |
| 4 | +from typing import TYPE_CHECKING, Any, Literal, overload |
5 | 5 |
|
6 | 6 | from public import public
|
7 | 7 |
|
|
17 | 17 | from ibis.util import deprecated, promote_list
|
18 | 18 |
|
19 | 19 | if TYPE_CHECKING:
|
| 20 | + import datetime |
| 21 | + import uuid |
| 22 | + |
20 | 23 | import pandas as pd
|
21 | 24 | import polars as pl
|
22 | 25 | import pyarrow as pa
|
@@ -135,6 +138,48 @@ def hash(self) -> ir.IntegerValue:
|
135 | 138 | """
|
136 | 139 | return ops.Hash(self).to_expr()
|
137 | 140 |
|
| 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 | + |
138 | 183 | def cast(self, target_type: Any) -> Value:
|
139 | 184 | """Cast expression to indicated data type.
|
140 | 185 |
|
@@ -1526,9 +1571,9 @@ def __pandas_result__(
|
1526 | 1571 | if data_mapper is None:
|
1527 | 1572 | from ibis.formats.pandas import PandasData as data_mapper
|
1528 | 1573 |
|
1529 |
| - assert len(df.columns) == 1, ( |
1530 |
| - "more than one column when converting columnar result DataFrame to Series" |
1531 |
| - ) |
| 1574 | + assert ( |
| 1575 | + len(df.columns) == 1 |
| 1576 | + ), "more than one column when converting columnar result DataFrame to Series" |
1532 | 1577 | # in theory we could use df.iloc[:, 0], but there seems to be a bug in
|
1533 | 1578 | # older geopandas where df.iloc[:, 0] doesn't return the same kind of
|
1534 | 1579 | # object as df.loc[:, column_name] when df is a GeoDataFrame
|
|
0 commit comments