|
22 | 22 | from __future__ import annotations |
23 | 23 |
|
24 | 24 | import warnings |
| 25 | +from collections.abc import Sequence |
25 | 26 | from typing import ( |
26 | 27 | TYPE_CHECKING, |
27 | 28 | Any, |
|
52 | 53 |
|
53 | 54 | if TYPE_CHECKING: |
54 | 55 | import pathlib |
55 | | - from typing import Callable, Sequence |
| 56 | + from typing import Callable |
56 | 57 |
|
57 | 58 | import pandas as pd |
58 | 59 | import polars as pl |
@@ -523,20 +524,28 @@ def with_column_renamed(self, old_name: str, new_name: str) -> DataFrame: |
523 | 524 |
|
524 | 525 | def aggregate( |
525 | 526 | self, |
526 | | - group_by: list[Expr | str] | Expr | str, |
527 | | - aggs: list[Expr] | Expr, |
| 527 | + group_by: Sequence[Expr | str] | Expr | str, |
| 528 | + aggs: Sequence[Expr] | Expr, |
528 | 529 | ) -> DataFrame: |
529 | 530 | """Aggregates the rows of the current DataFrame. |
530 | 531 |
|
531 | 532 | Args: |
532 | | - group_by: List of expressions or column names to group by. |
533 | | - aggs: List of expressions to aggregate. |
| 533 | + group_by: Sequence of expressions or column names to group by. |
| 534 | + aggs: Sequence of expressions to aggregate. |
534 | 535 |
|
535 | 536 | Returns: |
536 | 537 | DataFrame after aggregation. |
537 | 538 | """ |
538 | | - group_by_list = group_by if isinstance(group_by, list) else [group_by] |
539 | | - aggs_list = aggs if isinstance(aggs, list) else [aggs] |
| 539 | + group_by_list = ( |
| 540 | + list(group_by) |
| 541 | + if isinstance(group_by, Sequence) and not isinstance(group_by, (Expr, str)) |
| 542 | + else [group_by] |
| 543 | + ) |
| 544 | + aggs_list = ( |
| 545 | + list(aggs) |
| 546 | + if isinstance(aggs, Sequence) and not isinstance(aggs, Expr) |
| 547 | + else [aggs] |
| 548 | + ) |
540 | 549 |
|
541 | 550 | group_by_exprs = expr_list_to_raw_expr_list(group_by_list) |
542 | 551 | aggs_exprs = [ensure_expr(agg) for agg in aggs_list] |
|
0 commit comments