Skip to content

Commit 40b10d4

Browse files
refactor of init in consequence of last commit:
- _ExpressionLike -> IntoExpr - Expression | str -> IntoExprColumn
1 parent 7d1d912 commit 40b10d4

1 file changed

Lines changed: 19 additions & 69 deletions

File tree

_duckdb-stubs/__init__.pyi

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import datetime
2-
import decimal
31
import os
42
import pathlib
53
import typing
6-
import uuid
74
from typing_extensions import Self
5+
from ._expression import Expression
86

97
if typing.TYPE_CHECKING:
108
import fsspec
119
import numpy as np
1210
import polars
1311
import pandas
1412
import pyarrow.lib
15-
from collections.abc import Callable, Iterable, Sequence, Mapping
13+
from collections.abc import Callable, Iterable, Sequence
14+
from ._typing import ParquetFieldIdsType, IntoExpr, IntoExprColumn
1615
from duckdb import sqltypes, func
1716
from builtins import list as lst # needed to avoid mypy error on DuckDBPyRelation.list method shadowing
1817

@@ -491,9 +490,7 @@ class DuckDBPyRelation:
491490
def __getattr__(self, name: str) -> DuckDBPyRelation: ...
492491
def __getitem__(self, name: str) -> DuckDBPyRelation: ...
493492
def __len__(self) -> int: ...
494-
def aggregate(
495-
self, aggr_expr: str | Iterable[_ExpressionLike], group_expr: _ExpressionLike = ""
496-
) -> DuckDBPyRelation: ...
493+
def aggregate(self, aggr_expr: str | Iterable[IntoExpr], group_expr: IntoExpr = "") -> DuckDBPyRelation: ...
497494
def any_value(
498495
self, expression: str, groups: str = "", window_spec: str = "", projected_columns: str = ""
499496
) -> DuckDBPyRelation: ...
@@ -578,7 +575,7 @@ class DuckDBPyRelation:
578575
def fetchmany(self, size: typing.SupportsInt = 1) -> lst[tuple[typing.Any, ...]]: ...
579576
def fetchnumpy(self) -> dict[str, np.typing.NDArray[typing.Any] | pandas.Categorical]: ...
580577
def fetchone(self) -> tuple[typing.Any, ...] | None: ...
581-
def filter(self, filter_expr: Expression | str) -> DuckDBPyRelation: ...
578+
def filter(self, filter_expr: IntoExprColumn) -> DuckDBPyRelation: ...
582579
def first(self, expression: str, groups: str = "", projected_columns: str = "") -> DuckDBPyRelation: ...
583580
def first_value(self, expression: str, window_spec: str = "", projected_columns: str = "") -> DuckDBPyRelation: ...
584581
def fsum(
@@ -594,7 +591,7 @@ class DuckDBPyRelation:
594591
def join(
595592
self,
596593
other_rel: DuckDBPyRelation,
597-
condition: Expression | str,
594+
condition: IntoExprColumn,
598595
how: typing.Literal["inner", "left", "right", "outer", "semi", "anti"] = "inner",
599596
) -> DuckDBPyRelation: ...
600597
def lag(
@@ -665,7 +662,7 @@ class DuckDBPyRelation:
665662
def product(
666663
self, expression: str, groups: str = "", window_spec: str = "", projected_columns: str = ""
667664
) -> DuckDBPyRelation: ...
668-
def project(self, *args: _ExpressionLike, groups: str = "") -> DuckDBPyRelation: ...
665+
def project(self, *args: IntoExpr, groups: str = "") -> DuckDBPyRelation: ...
669666
def quantile(
670667
self,
671668
expression: str,
@@ -694,6 +691,9 @@ class DuckDBPyRelation:
694691
def rank(self, window_spec: str, projected_columns: str = "") -> DuckDBPyRelation: ...
695692
def rank_dense(self, window_spec: str, projected_columns: str = "") -> DuckDBPyRelation: ...
696693
def row_number(self, window_spec: str, projected_columns: str = "") -> DuckDBPyRelation: ...
694+
def select(self, *args: IntoExpr, groups: str = "") -> DuckDBPyRelation: ...
695+
def select_dtypes(self, types: list[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
696+
def select_types(self, types: list[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
697697
def select(self, *args: _ExpressionLike, groups: str = "") -> DuckDBPyRelation: ...
698698
def select_dtypes(self, types: lst[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
699699
def select_types(self, types: lst[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
@@ -707,7 +707,7 @@ class DuckDBPyRelation:
707707
null_value: str | None = None,
708708
render_mode: RenderMode | None = None,
709709
) -> None: ...
710-
def sort(self, *args: _ExpressionLike) -> DuckDBPyRelation: ...
710+
def sort(self, *args: IntoExpr) -> DuckDBPyRelation: ...
711711
def sql_query(self) -> str: ...
712712
def std(
713713
self, expression: str, groups: str = "", window_spec: str = "", projected_columns: str = ""
@@ -771,7 +771,7 @@ class DuckDBPyRelation:
771771
def torch(self) -> dict[str, typing.Any]: ...
772772
def union(self, union_rel: DuckDBPyRelation) -> DuckDBPyRelation: ...
773773
def unique(self, unique_aggr: str) -> DuckDBPyRelation: ...
774-
def update(self, set: dict[str, _ExpressionLike], *, condition: _ExpressionLike | None = None) -> None: ...
774+
def update(self, set: dict[str, IntoExpr], *, condition: IntoExpr = None) -> None: ...
775775
def value_counts(self, expression: str, groups: str = "") -> DuckDBPyRelation: ...
776776
def var(
777777
self, expression: str, groups: str = "", window_spec: str = "", projected_columns: str = ""
@@ -878,56 +878,6 @@ class ExplainType:
878878
@property
879879
def value(self) -> int: ...
880880

881-
class Expression:
882-
def __add__(self, other: _ExpressionLike) -> Expression: ...
883-
def __and__(self, other: _ExpressionLike) -> Expression: ...
884-
def __div__(self, other: _ExpressionLike) -> Expression: ...
885-
def __eq__(self, other: _ExpressionLike) -> Expression: ... # type: ignore[override]
886-
def __floordiv__(self, other: _ExpressionLike) -> Expression: ...
887-
def __ge__(self, other: _ExpressionLike) -> Expression: ...
888-
def __gt__(self, other: _ExpressionLike) -> Expression: ...
889-
@typing.overload
890-
def __init__(self, arg0: str) -> None: ...
891-
@typing.overload
892-
def __init__(self, arg0: typing.Any) -> None: ...
893-
def __invert__(self) -> Expression: ...
894-
def __le__(self, other: _ExpressionLike) -> Expression: ...
895-
def __lt__(self, other: _ExpressionLike) -> Expression: ...
896-
def __mod__(self, other: _ExpressionLike) -> Expression: ...
897-
def __mul__(self, other: _ExpressionLike) -> Expression: ...
898-
def __ne__(self, other: _ExpressionLike) -> Expression: ... # type: ignore[override]
899-
def __neg__(self) -> Expression: ...
900-
def __or__(self, other: _ExpressionLike) -> Expression: ...
901-
def __pow__(self, other: _ExpressionLike) -> Expression: ...
902-
def __radd__(self, other: _ExpressionLike) -> Expression: ...
903-
def __rand__(self, other: _ExpressionLike) -> Expression: ...
904-
def __rdiv__(self, other: _ExpressionLike) -> Expression: ...
905-
def __rfloordiv__(self, other: _ExpressionLike) -> Expression: ...
906-
def __rmod__(self, other: _ExpressionLike) -> Expression: ...
907-
def __rmul__(self, other: _ExpressionLike) -> Expression: ...
908-
def __ror__(self, other: _ExpressionLike) -> Expression: ...
909-
def __rpow__(self, other: _ExpressionLike) -> Expression: ...
910-
def __rsub__(self, other: _ExpressionLike) -> Expression: ...
911-
def __rtruediv__(self, other: _ExpressionLike) -> Expression: ...
912-
def __sub__(self, other: _ExpressionLike) -> Expression: ...
913-
def __truediv__(self, other: _ExpressionLike) -> Expression: ...
914-
def alias(self, name: str) -> Expression: ...
915-
def asc(self) -> Expression: ...
916-
def between(self, lower: _ExpressionLike, upper: _ExpressionLike) -> Expression: ...
917-
def cast(self, type: sqltypes.DuckDBPyType) -> Expression: ...
918-
def collate(self, collation: str) -> Expression: ...
919-
def desc(self) -> Expression: ...
920-
def get_name(self) -> str: ...
921-
def isin(self, *args: _ExpressionLike) -> Expression: ...
922-
def isnotin(self, *args: _ExpressionLike) -> Expression: ...
923-
def isnotnull(self) -> Expression: ...
924-
def isnull(self) -> Expression: ...
925-
def nulls_first(self) -> Expression: ...
926-
def nulls_last(self) -> Expression: ...
927-
def otherwise(self, value: _ExpressionLike) -> Expression: ...
928-
def show(self) -> None: ...
929-
def when(self, condition: _ExpressionLike, value: _ExpressionLike) -> Expression: ...
930-
931881
class FatalException(DatabaseError): ...
932882

933883
class HTTPException(IOException):
@@ -1078,18 +1028,18 @@ class token_type:
10781028
@property
10791029
def value(self) -> int: ...
10801030

1081-
def CaseExpression(condition: _ExpressionLike, value: _ExpressionLike) -> Expression: ...
1082-
def CoalesceOperator(*args: _ExpressionLike) -> Expression: ...
1031+
def CaseExpression(condition: IntoExpr, value: IntoExpr) -> Expression: ...
1032+
def CoalesceOperator(*args: IntoExpr) -> Expression: ...
10831033
def ColumnExpression(*args: str) -> Expression: ...
10841034
def ConstantExpression(value: typing.Any) -> Expression: ...
10851035
def DefaultExpression() -> Expression: ...
1086-
def FunctionExpression(function_name: str, *args: _ExpressionLike) -> Expression: ...
1087-
def LambdaExpression(lhs: typing.Any, rhs: _ExpressionLike) -> Expression: ...
1036+
def FunctionExpression(function_name: str, *args: IntoExpr) -> Expression: ...
1037+
def LambdaExpression(lhs: typing.Any, rhs: IntoExpr) -> Expression: ...
10881038
def SQLExpression(expression: str) -> Expression: ...
10891039
def StarExpression(*, exclude: Iterable[str | Expression] | None = None) -> Expression: ...
10901040
def aggregate(
10911041
df: pandas.DataFrame,
1092-
aggr_expr: str | Iterable[_ExpressionLike],
1042+
aggr_expr: str | Iterable[IntoExpr],
10931043
group_expr: str = "",
10941044
*,
10951045
connection: DuckDBPyConnection | None = None,
@@ -1203,7 +1153,7 @@ def fetchone(*, connection: DuckDBPyConnection | None = None) -> tuple[typing.An
12031153
def filesystem_is_registered(name: str, *, connection: DuckDBPyConnection | None = None) -> bool: ...
12041154
def filter(
12051155
df: pandas.DataFrame,
1206-
filter_expr: Expression | str,
1156+
filter_expr: IntoExprColumn,
12071157
*,
12081158
connection: DuckDBPyConnection | None = None,
12091159
) -> DuckDBPyRelation: ...
@@ -1347,7 +1297,7 @@ def pl(
13471297
connection: DuckDBPyConnection | None = None,
13481298
) -> polars.DataFrame | polars.LazyFrame: ...
13491299
def project(
1350-
df: pandas.DataFrame, *args: _ExpressionLike, groups: str = "", connection: DuckDBPyConnection | None = None
1300+
df: pandas.DataFrame, *args: IntoExpr, groups: str = "", connection: DuckDBPyConnection | None = None
13511301
) -> DuckDBPyRelation: ...
13521302
def query(
13531303
query: Statement | str,

0 commit comments

Comments
 (0)