Skip to content

Commit afba0ab

Browse files
OutSquareCapitalevertlammerts
authored andcommitted
Typing : added ParquetCompression and ProfilerFormat literals
1 parent 1c610f6 commit afba0ab

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

_duckdb-stubs/__init__.pyi

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ if typing.TYPE_CHECKING:
3838
CsvCompression,
3939
HiveTypes,
4040
ColumnsTypes,
41+
ProfilerFormat,
42+
ParquetCompression,
4143
)
4244
from ._enums import ExplainTypeLiteral, CSVLineTerminatorLiteral, RenderModeLiteral
4345
from duckdb import sqltypes, func
@@ -302,7 +304,7 @@ class DuckDBPyConnection:
302304
filename: bool = False,
303305
hive_partitioning: bool = False,
304306
union_by_name: bool = False,
305-
compression: str | None = None,
307+
compression: ParquetCompression | None = None,
306308
) -> DuckDBPyRelation: ...
307309
@typing.overload
308310
def from_parquet(
@@ -314,7 +316,7 @@ class DuckDBPyConnection:
314316
filename: bool = False,
315317
hive_partitioning: bool = False,
316318
union_by_name: bool = False,
317-
compression: str | None = None,
319+
compression: ParquetCompression | None = None,
318320
) -> DuckDBPyRelation: ...
319321
def from_query(self, query: str, *, alias: str = "", params: object = None) -> DuckDBPyRelation: ...
320322
def get_table_names(self, query: str, *, qualified: bool = False) -> set[str]: ...
@@ -327,7 +329,7 @@ class DuckDBPyConnection:
327329
repository_url: str | None = None,
328330
version: str | None = None,
329331
) -> None: ...
330-
def get_profiling_information(self, format: str = "json") -> str: ...
332+
def get_profiling_information(self, format: ProfilerFormat = "json") -> str: ...
331333
def enable_profiling(self) -> None: ...
332334
def disable_profiling(self) -> None: ...
333335
def interrupt(self) -> None: ...
@@ -426,7 +428,7 @@ class DuckDBPyConnection:
426428
filename: bool = False,
427429
hive_partitioning: bool = False,
428430
union_by_name: bool = False,
429-
compression: str | None = None,
431+
compression: ParquetCompression | None = None,
430432
) -> DuckDBPyRelation: ...
431433
@typing.overload
432434
def read_parquet(
@@ -438,7 +440,7 @@ class DuckDBPyConnection:
438440
filename: bool = False,
439441
hive_partitioning: bool = False,
440442
union_by_name: bool = False,
441-
compression: typing.Any = None,
443+
compression: ParquetCompression | None = None,
442444
) -> DuckDBPyRelation: ...
443445
def register(self, view_name: str, python_object: object) -> DuckDBPyConnection: ...
444446
def register_filesystem(self, filesystem: fsspec.AbstractFileSystem) -> None: ...
@@ -725,7 +727,7 @@ class DuckDBPyRelation:
725727
self,
726728
file_name: str,
727729
*,
728-
compression: str | None = None,
730+
compression: ParquetCompression | None = None,
729731
field_ids: ParquetFieldsOptions | None = None,
730732
row_group_size_bytes: int | str | None = None,
731733
row_group_size: int | None = None,
@@ -781,7 +783,7 @@ class DuckDBPyRelation:
781783
self,
782784
file_name: str,
783785
*,
784-
compression: str | None = None,
786+
compression: ParquetCompression | None = None,
785787
field_ids: ParquetFieldsOptions | None = None,
786788
row_group_size_bytes: str | int | None = None,
787789
row_group_size: int | None = None,
@@ -1039,7 +1041,7 @@ def from_parquet(
10391041
filename: bool = False,
10401042
hive_partitioning: bool = False,
10411043
union_by_name: bool = False,
1042-
compression: str | None = None,
1044+
compression: ParquetCompression | None = None,
10431045
connection: DuckDBPyConnection | None = None,
10441046
) -> DuckDBPyRelation: ...
10451047
@typing.overload
@@ -1051,7 +1053,7 @@ def from_parquet(
10511053
filename: bool = False,
10521054
hive_partitioning: bool = False,
10531055
union_by_name: bool = False,
1054-
compression: typing.Any = None,
1056+
compression: ParquetCompression | None = None,
10551057
connection: DuckDBPyConnection | None = None,
10561058
) -> DuckDBPyRelation: ...
10571059
def from_query(
@@ -1081,7 +1083,9 @@ def limit(
10811083
*,
10821084
connection: DuckDBPyConnection | None = None,
10831085
) -> DuckDBPyRelation: ...
1084-
def get_profiling_information(*, connection: DuckDBPyConnection | None = None, format: str = "json") -> str: ...
1086+
def get_profiling_information(
1087+
*, connection: DuckDBPyConnection | None = None, format: ProfilerFormat = "json"
1088+
) -> str: ...
10851089
def enable_profiling(*, connection: DuckDBPyConnection | None = None) -> None: ...
10861090
def disable_profiling(*, connection: DuckDBPyConnection | None = None) -> None: ...
10871091
def list_filesystems(*, connection: DuckDBPyConnection | None = None) -> lst[str]: ...
@@ -1208,7 +1212,7 @@ def read_parquet(
12081212
filename: bool = False,
12091213
hive_partitioning: bool = False,
12101214
union_by_name: bool = False,
1211-
compression: str | None = None,
1215+
compression: ParquetCompression | None = None,
12121216
connection: DuckDBPyConnection | None = None,
12131217
) -> DuckDBPyRelation: ...
12141218
@typing.overload
@@ -1220,7 +1224,7 @@ def read_parquet(
12201224
filename: bool = False,
12211225
hive_partitioning: bool = False,
12221226
union_by_name: bool = False,
1223-
compression: typing.Any = None,
1227+
compression: ParquetCompression | None = None,
12241228
connection: DuckDBPyConnection | None = None,
12251229
) -> DuckDBPyRelation: ...
12261230
def register(

_duckdb-stubs/_typing.pyi

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ PyTypeIds: TypeAlias = Builtins | NestedIds
138138
StrIntoPyType: TypeAlias = Builtins | Literal["json"] | str
139139
"""Any `str` that can be converted into a `DuckDBPyType`.
140140
141-
The pytypes not present in the literal values are the composed ones, like `STRUCT` or `DECIMAL`.
141+
The `DuckDBPyType` not present in the literal values are the composed ones, like `STRUCT` or `DECIMAL`.
142142
143143
Note:
144144
A `StrEnum` will be handled the same way as a `str`."""
@@ -186,21 +186,28 @@ _Auto: TypeAlias = Literal["auto"]
186186
ParquetFieldsOptions: TypeAlias = _Auto | ParquetFieldIdsType
187187
"""Types accepted for the `field_ids` parameter in parquet writing methods."""
188188

189-
_CompressionOptions: TypeAlias = Literal["none", "gzip", "zstd"]
190-
"""Generally available compression options."""
191-
192-
CsvCompression: TypeAlias = _Auto | _CompressionOptions
193189
CsvEncoding: TypeAlias = Literal["utf-8", "utf-16", "latin-1"] | str
194190
"""Encdoding options.
195191
196192
All availables options not in the literal values can be seen here:
197193
https://duckdb.org/docs/stable/core_extensions/encodings
198194
"""
199-
JsonCompression: TypeAlias = Literal["auto_detect"] | _CompressionOptions
200195
JsonFormat: TypeAlias = _Auto | Literal["unstructured", "newline_delimited", "array"]
201196
JsonRecordOptions: TypeAlias = _Auto | Literal["true", "false"]
202197

198+
# compression kinds
199+
200+
_CompressionOptions: TypeAlias = Literal["gzip", "zstd"]
201+
"""Generally available compression options."""
202+
_None: TypeAlias = Literal["none"]
203+
CsvCompression: TypeAlias = _Auto | _None | _CompressionOptions
204+
JsonCompression: TypeAlias = Literal["auto_detect"] | _None | _CompressionOptions
205+
ParquetCompression: TypeAlias = Literal["uncompressed", "brotli", "snappy", "lz4", "lz4_raw"] | _CompressionOptions
206+
203207
# Other
204208

205209
JoinType: TypeAlias = Literal["inner", "left", "right", "outer", "semi", "anti"]
206210
"""Types of join accepted by `DuckDBPyRelation.join` method."""
211+
212+
ProfilerFormat: TypeAlias = Literal["json", "query_tree", "query_tree_optimizer", "no_output", "html", "graphviz"]
213+
"""Formats available in `get_profiling_information` method/function."""

0 commit comments

Comments
 (0)