Skip to content

Commit 35a0b80

Browse files
committed
refactor: update type hints for file_sort_order and sort_list parameters to use Sequence for improved consistency
1 parent 46dbc85 commit 35a0b80

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

python/datafusion/context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from __future__ import annotations
2121

2222
import warnings
23-
from typing import TYPE_CHECKING, Any, Protocol
23+
from typing import TYPE_CHECKING, Any, Protocol, Sequence
2424

2525
import pyarrow as pa
2626

@@ -553,7 +553,7 @@ def register_listing_table(
553553
table_partition_cols: list[tuple[str, str | pa.DataType]] | None = None,
554554
file_extension: str = ".parquet",
555555
schema: pa.Schema | None = None,
556-
file_sort_order: list[list[SortKey]] | None = None,
556+
file_sort_order: Sequence[Sequence[SortKey]] | None = None,
557557
) -> None:
558558
"""Register multiple files as a single table.
559559
@@ -805,7 +805,7 @@ def register_parquet(
805805
file_extension: str = ".parquet",
806806
skip_metadata: bool = True,
807807
schema: pa.Schema | None = None,
808-
file_sort_order: list[list[SortKey]] | None = None,
808+
file_sort_order: Sequence[Sequence[SortKey]] | None = None,
809809
) -> None:
810810
"""Register a Parquet file as a table.
811811
@@ -1096,7 +1096,7 @@ def read_parquet(
10961096
file_extension: str = ".parquet",
10971097
skip_metadata: bool = True,
10981098
schema: pa.Schema | None = None,
1099-
file_sort_order: list[list[SortKey]] | None = None,
1099+
file_sort_order: Sequence[Sequence[SortKey]] | None = None,
11001100
) -> DataFrame:
11011101
"""Read a Parquet source into a :py:class:`~datafusion.dataframe.Dataframe`.
11021102
@@ -1176,9 +1176,9 @@ def execute(self, plan: ExecutionPlan, partitions: int) -> RecordBatchStream:
11761176

11771177
@staticmethod
11781178
def _convert_file_sort_order(
1179-
file_sort_order: list[list[SortKey]] | None,
1179+
file_sort_order: Sequence[Sequence[SortKey]] | None,
11801180
) -> list[list[Any]] | None:
1181-
"""Convert nested ``SortKey`` lists into raw sort representations.
1181+
"""Convert nested ``SortKey`` sequences into raw sort representations.
11821182
11831183
Each ``SortKey`` can be a column name string, an ``Expr``, or a
11841184
``SortExpr`` and will be converted using

python/datafusion/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def sort(self, *exprs: SortKey) -> DataFrame:
567567
Returns:
568568
DataFrame after sorting.
569569
"""
570-
exprs_raw = sort_list_to_raw_sort_list(list(exprs))
570+
exprs_raw = sort_list_to_raw_sort_list(exprs)
571571
return DataFrame(self.df.sort(*exprs_raw))
572572

573573
def cast(self, mapping: dict[str, pa.DataType[Any]]) -> DataFrame:

python/datafusion/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def sort_or_default(e: Expr | SortExpr) -> expr_internal.SortExpr:
253253

254254

255255
def sort_list_to_raw_sort_list(
256-
sort_list: Optional[list[SortKey] | SortKey],
256+
sort_list: Optional[Sequence[SortKey] | SortKey],
257257
) -> Optional[list[expr_internal.SortExpr]]:
258258
"""Helper function to return an optional sort list to raw variant."""
259259
if isinstance(sort_list, (Expr, SortExpr, str)):

0 commit comments

Comments
 (0)