Skip to content

Commit 92c906a

Browse files
feat:
- added various new literals for files arguments - moved join "how" literal in _typing for centralization - renamed IntoNestedDType -> IntoFields
1 parent 60e92cc commit 92c906a

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

_duckdb-stubs/__init__.pyi

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ if typing.TYPE_CHECKING:
1919
PythonLiteral,
2020
IntoValues,
2121
IntoDType,
22-
IntoNestedDType,
22+
IntoFields,
23+
JoinType,
2324
)
2425
from duckdb import sqltypes, func
2526

@@ -447,17 +448,17 @@ class DuckDBPyConnection:
447448
def register_filesystem(self, filesystem: fsspec.AbstractFileSystem) -> None: ...
448449
def remove_function(self, name: str) -> DuckDBPyConnection: ...
449450
def rollback(self) -> DuckDBPyConnection: ...
450-
def row_type(self, fields: IntoNestedDType) -> sqltypes.DuckDBPyType: ...
451+
def row_type(self, fields: IntoFields) -> sqltypes.DuckDBPyType: ...
451452
def sql(self, query: Statement | str, *, alias: str = "", params: object = None) -> DuckDBPyRelation: ...
452453
def sqltype(self, type_str: str) -> sqltypes.DuckDBPyType: ...
453454
def string_type(self, collation: str = "") -> sqltypes.DuckDBPyType: ...
454-
def struct_type(self, fields: IntoNestedDType) -> sqltypes.DuckDBPyType: ...
455+
def struct_type(self, fields: IntoFields) -> sqltypes.DuckDBPyType: ...
455456
def table(self, table_name: str) -> DuckDBPyRelation: ...
456457
def table_function(self, name: str, parameters: object = None) -> DuckDBPyRelation: ...
457458
def tf(self) -> dict[str, typing.Any]: ...
458459
def torch(self) -> dict[str, typing.Any]: ...
459460
def type(self, type_str: str) -> sqltypes.DuckDBPyType: ...
460-
def union_type(self, members: IntoNestedDType) -> sqltypes.DuckDBPyType: ...
461+
def union_type(self, members: IntoFields) -> sqltypes.DuckDBPyType: ...
461462
def unregister(self, view_name: str) -> DuckDBPyConnection: ...
462463
def unregister_filesystem(self, name: str) -> None: ...
463464
def values(self, *args: IntoValues) -> DuckDBPyRelation: ...
@@ -571,12 +572,7 @@ class DuckDBPyRelation:
571572
def insert(self, values: lst[object]) -> None: ...
572573
def insert_into(self, table_name: str) -> None: ...
573574
def intersect(self, other_rel: Self) -> DuckDBPyRelation: ...
574-
def join(
575-
self,
576-
other_rel: Self,
577-
condition: IntoExprColumn,
578-
how: typing.Literal["inner", "left", "right", "outer", "semi", "anti"] = "inner",
579-
) -> DuckDBPyRelation: ...
575+
def join(self, other_rel: Self, condition: IntoExprColumn, how: JoinType = "inner") -> DuckDBPyRelation: ...
580576
def lag(
581577
self,
582578
expression: str,
@@ -1391,7 +1387,7 @@ def register_filesystem(
13911387
) -> None: ...
13921388
def remove_function(name: str, *, connection: DuckDBPyConnection | None = None) -> DuckDBPyConnection: ...
13931389
def rollback(*, connection: DuckDBPyConnection | None = None) -> DuckDBPyConnection: ...
1394-
def row_type(fields: IntoNestedDType, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
1390+
def row_type(fields: IntoFields, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
13951391
def rowcount(*, connection: DuckDBPyConnection | None = None) -> int: ...
13961392
def set_default_connection(connection: DuckDBPyConnection) -> None: ...
13971393
def sql(
@@ -1403,7 +1399,7 @@ def sql(
14031399
) -> DuckDBPyRelation: ...
14041400
def sqltype(type_str: str, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
14051401
def string_type(collation: str = "", *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
1406-
def struct_type(fields: IntoNestedDType, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
1402+
def struct_type(fields: IntoFields, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
14071403
def table(table_name: str, *, connection: DuckDBPyConnection | None = None) -> DuckDBPyRelation: ...
14081404
def table_function(
14091405
name: str,
@@ -1415,7 +1411,7 @@ def tf(*, connection: DuckDBPyConnection | None = None) -> dict[str, typing.Any]
14151411
def tokenize(query: str) -> lst[tuple[int, token_type]]: ...
14161412
def torch(*, connection: DuckDBPyConnection | None = None) -> dict[str, typing.Any]: ...
14171413
def type(type_str: str, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
1418-
def union_type(members: IntoNestedDType, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
1414+
def union_type(members: IntoFields, *, connection: DuckDBPyConnection | None = None) -> sqltypes.DuckDBPyType: ...
14191415
def unregister(view_name: str, *, connection: DuckDBPyConnection | None = None) -> DuckDBPyConnection: ...
14201416
def unregister_filesystem(name: str, *, connection: DuckDBPyConnection | None = None) -> None: ...
14211417
def values(*args: IntoValues, connection: DuckDBPyConnection | None = None) -> DuckDBPyRelation: ...

_duckdb-stubs/_typing.pyi

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ See Also:
8888
https://duckdb.org/docs/stable/clients/python/conversion
8989
"""
9090

91-
# the field_ids argument to to_parquet and write_parquet has a recursive structure
92-
ParquetFieldIdsType: TypeAlias = Mapping[str, int | ParquetFieldIdsType]
9391
IntoValues: TypeAlias = list[PythonLiteral] | tuple[Expression, ...] | Expression
9492
"""Types that can be converted to a table."""
9593
# Datatypes conversions
@@ -140,7 +138,7 @@ DTypeIdentifiers: TypeAlias = Builtins | NestedIds
140138
StrIntoDType = Builtins | Literal["json"] | str
141139
"""Any `str` that can be converted into a `DuckDBPyType`.
142140
143-
The dtypes not present in the literal values are the composed ones, like `STRUCT` or `DECIMAL`
141+
The dtypes not present in the literal values are the composed ones, like `STRUCT` or `DECIMAL`.
144142
145143
Note:
146144
A `StrEnum` will be handled the same way as a `str`."""
@@ -166,7 +164,7 @@ See Also:
166164

167165
# NOTE: here we keep the covariance "hack" and warn the user in the docstring,
168166
# because otherwise we can just resort to `Any` for the `dict` and `list` types.
169-
IntoNestedDType: TypeAlias = Mapping[str, IntoDType] | Sequence[IntoDType]
167+
IntoFields: TypeAlias = Mapping[str, IntoDType] | Sequence[IntoDType]
170168
"""Types that can be converted either into:
171169
172170
- a nested `DuckDBPyType` (e.g. `STRUCT` or `UNION`)
@@ -176,3 +174,33 @@ Warning:
176174
Only `dict` and `list` containers are accepted at runtime.
177175
We use `Mapping` and `Sequence` here to satisfy the covariance of the element types.
178176
"""
177+
178+
# Files related
179+
180+
# NOTE: ideally HiveTypes should also be accepted as a Mapping[str, StrIntoDType].
181+
ColumnsTypes: TypeAlias = Mapping[str, StrIntoDType]
182+
HiveTypes: TypeAlias = dict[str, StrIntoDType]
183+
ParquetFieldIdsType: TypeAlias = Mapping[str, int | ParquetFieldIdsType]
184+
185+
_Auto: TypeAlias = Literal["auto"]
186+
ParquetFieldsOptions: TypeAlias = _Auto | ParquetFieldIdsType
187+
"""Types accepted for the `field_ids` parameter in parquet writing methods."""
188+
189+
_CompressionOptions: TypeAlias = Literal["none", "gzip", "zstd"]
190+
"""Generally available compression options."""
191+
192+
CsvCompression: TypeAlias = _Auto | _CompressionOptions
193+
CsvEncoding: TypeAlias = Literal["utf-8", "utf-16", "latin-1"] | str
194+
"""Encdoding options.
195+
196+
All availables options not in the literal values can be seen here:
197+
https://duckdb.org/docs/stable/core_extensions/encodings
198+
"""
199+
JsonCompression: TypeAlias = _CompressionOptions | Literal["auto_detect"]
200+
JsonFormat: TypeAlias = _Auto | Literal["unstructured", "newline_delimited", "array"]
201+
JsonRecordOptions: TypeAlias = _Auto | Literal["true", "false"]
202+
203+
# Other
204+
205+
JoinType = Literal["inner", "left", "right", "outer", "semi", "anti"]
206+
"""Types of join accepted by `DuckDBPyRelation.join` method."""

0 commit comments

Comments
 (0)