Skip to content

Commit 54ef231

Browse files
- using python 3.10 modern typing syntax everywhere for Union and List
- added Literal for DuckDBPyRelation.join "how" argument possible choices
1 parent f30912e commit 54ef231

1 file changed

Lines changed: 37 additions & 34 deletions

File tree

_duckdb-stubs/__init__.pyi

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ if typing.TYPE_CHECKING:
1616
from duckdb import sqltypes, func
1717

1818
# the field_ids argument to to_parquet and write_parquet has a recursive structure
19-
ParquetFieldIdsType = Mapping[str, typing.Union[int, "ParquetFieldIdsType"]]
19+
ParquetFieldIdsType = Mapping[str, int | "ParquetFieldIdsType"]
2020

21-
_ExpressionLike: typing.TypeAlias = typing.Union[
22-
"Expression",
23-
str,
24-
int,
25-
float,
26-
bool,
27-
bytes,
28-
None,
29-
datetime.date,
30-
datetime.datetime,
31-
datetime.time,
32-
datetime.timedelta,
33-
decimal.Decimal,
34-
uuid.UUID,
35-
]
21+
_ExpressionLike: typing.TypeAlias = (
22+
"Expression"
23+
| str
24+
| int
25+
| float
26+
| bool
27+
| bytes
28+
| None
29+
| datetime.date
30+
| datetime.datetime
31+
| datetime.time
32+
| datetime.timedelta
33+
| decimal.Decimal
34+
| uuid.UUID
35+
)
3636

3737
__all__: list[str] = [
3838
"BinderException",
@@ -358,7 +358,7 @@ class DuckDBPyConnection:
358358
@typing.overload
359359
def pl(
360360
self, rows_per_batch: typing.SupportsInt = 1000000, *, lazy: bool = False
361-
) -> typing.Union[polars.DataFrame, polars.LazyFrame]: ...
361+
) -> polars.DataFrame | polars.LazyFrame: ...
362362
def query(self, query: str, *, alias: str = "", params: object = None) -> DuckDBPyRelation: ...
363363
def query_progress(self) -> float: ...
364364
def read_csv(
@@ -587,11 +587,14 @@ class DuckDBPyRelation:
587587
def histogram(
588588
self, expression: str, groups: str = "", window_spec: str = "", projected_columns: str = ""
589589
) -> DuckDBPyRelation: ...
590-
def insert(self, values: typing.List[object]) -> None: ...
590+
def insert(self, values: list[object]) -> None: ...
591591
def insert_into(self, table_name: str) -> None: ...
592592
def intersect(self, other_rel: DuckDBPyRelation) -> DuckDBPyRelation: ...
593593
def join(
594-
self, other_rel: DuckDBPyRelation, condition: Expression | str, how: str = "inner"
594+
self,
595+
other_rel: DuckDBPyRelation,
596+
condition: Expression | str,
597+
how: typing.Literal["inner", "left", "right", "outer", "semi", "anti"] = "inner",
595598
) -> DuckDBPyRelation: ...
596599
def lag(
597600
self,
@@ -657,31 +660,31 @@ class DuckDBPyRelation:
657660
@typing.overload
658661
def pl(
659662
self, batch_size: typing.SupportsInt = 1000000, *, lazy: bool = False
660-
) -> typing.Union[polars.DataFrame, polars.LazyFrame]: ...
663+
) -> polars.DataFrame | polars.LazyFrame: ...
661664
def product(
662665
self, expression: str, groups: str = "", window_spec: str = "", projected_columns: str = ""
663666
) -> DuckDBPyRelation: ...
664667
def project(self, *args: _ExpressionLike, groups: str = "") -> DuckDBPyRelation: ...
665668
def quantile(
666669
self,
667670
expression: str,
668-
q: float | typing.List[float] = 0.5,
671+
q: float | list[float] = 0.5,
669672
groups: str = "",
670673
window_spec: str = "",
671674
projected_columns: str = "",
672675
) -> DuckDBPyRelation: ...
673676
def quantile_cont(
674677
self,
675678
expression: str,
676-
q: float | typing.List[float] = 0.5,
679+
q: float | list[float] = 0.5,
677680
groups: str = "",
678681
window_spec: str = "",
679682
projected_columns: str = "",
680683
) -> DuckDBPyRelation: ...
681684
def quantile_disc(
682685
self,
683686
expression: str,
684-
q: float | typing.List[float] = 0.5,
687+
q: float | list[float] = 0.5,
685688
groups: str = "",
686689
window_spec: str = "",
687690
projected_columns: str = "",
@@ -691,8 +694,8 @@ class DuckDBPyRelation:
691694
def rank_dense(self, window_spec: str, projected_columns: str = "") -> DuckDBPyRelation: ...
692695
def row_number(self, window_spec: str, projected_columns: str = "") -> DuckDBPyRelation: ...
693696
def select(self, *args: _ExpressionLike, groups: str = "") -> DuckDBPyRelation: ...
694-
def select_dtypes(self, types: typing.List[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
695-
def select_types(self, types: typing.List[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
697+
def select_dtypes(self, types: list[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
698+
def select_types(self, types: list[sqltypes.DuckDBPyType | str]) -> DuckDBPyRelation: ...
696699
def set_alias(self, alias: str) -> DuckDBPyRelation: ...
697700
def show(
698701
self,
@@ -741,7 +744,7 @@ class DuckDBPyRelation:
741744
overwrite: bool | None = None,
742745
per_thread_output: bool | None = None,
743746
use_tmp_file: bool | None = None,
744-
partition_by: typing.List[str] | None = None,
747+
partition_by: list[str] | None = None,
745748
write_partition_columns: bool | None = None,
746749
) -> None: ...
747750
def to_df(self, *, date_as_object: bool = False) -> pandas.DataFrame: ...
@@ -756,7 +759,7 @@ class DuckDBPyRelation:
756759
overwrite: bool | None = None,
757760
per_thread_output: bool | None = None,
758761
use_tmp_file: bool | None = None,
759-
partition_by: typing.List[str] | None = None,
762+
partition_by: list[str] | None = None,
760763
write_partition_columns: bool | None = None,
761764
append: bool | None = None,
762765
filename_pattern: str | None = None,
@@ -798,7 +801,7 @@ class DuckDBPyRelation:
798801
overwrite: bool | None = None,
799802
per_thread_output: bool | None = None,
800803
use_tmp_file: bool | None = None,
801-
partition_by: typing.List[str] | None = None,
804+
partition_by: list[str] | None = None,
802805
write_partition_columns: bool | None = None,
803806
) -> None: ...
804807
def write_parquet(
@@ -812,7 +815,7 @@ class DuckDBPyRelation:
812815
overwrite: bool | None = None,
813816
per_thread_output: bool | None = None,
814817
use_tmp_file: bool | None = None,
815-
partition_by: typing.List[str] | None = None,
818+
partition_by: list[str] | None = None,
816819
write_partition_columns: bool | None = None,
817820
append: bool | None = None,
818821
filename_pattern: str | None = None,
@@ -821,17 +824,17 @@ class DuckDBPyRelation:
821824
@property
822825
def alias(self) -> str: ...
823826
@property
824-
def columns(self) -> typing.List[str]: ...
827+
def columns(self) -> list[str]: ...
825828
@property
826-
def description(self) -> typing.List[tuple[str, sqltypes.DuckDBPyType, None, None, None, None, None]]: ...
829+
def description(self) -> list[tuple[str, sqltypes.DuckDBPyType, None, None, None, None, None]]: ...
827830
@property
828-
def dtypes(self) -> typing.List[sqltypes.DuckDBPyType]: ...
831+
def dtypes(self) -> list[sqltypes.DuckDBPyType]: ...
829832
@property
830833
def shape(self) -> tuple[int, int]: ...
831834
@property
832835
def type(self) -> str: ...
833836
@property
834-
def types(self) -> typing.List[sqltypes.DuckDBPyType]: ...
837+
def types(self) -> list[sqltypes.DuckDBPyType]: ...
835838

836839
class Error(Exception): ...
837840

@@ -1341,7 +1344,7 @@ def pl(
13411344
*,
13421345
lazy: bool = False,
13431346
connection: DuckDBPyConnection | None = None,
1344-
) -> typing.Union[polars.DataFrame, polars.LazyFrame]: ...
1347+
) -> polars.DataFrame | polars.LazyFrame: ...
13451348
def project(
13461349
df: pandas.DataFrame, *args: _ExpressionLike, groups: str = "", connection: DuckDBPyConnection | None = None
13471350
) -> DuckDBPyRelation: ...

0 commit comments

Comments
 (0)