|
6 | 6 | from .dataframe_object import DataFrame
|
7 | 7 |
|
8 | 8 |
|
9 |
| -__all__ = ['GroupBy'] |
| 9 | +__all__ = [ |
| 10 | + "Aggregation", |
| 11 | + "GroupBy", |
| 12 | +] |
10 | 13 |
|
11 | 14 |
|
12 | 15 | class GroupBy(Protocol):
|
@@ -51,3 +54,75 @@ def var(self, *, correction: int | float = 1, skip_nulls: bool = True) -> DataFr
|
51 | 54 |
|
52 | 55 | def size(self) -> DataFrame:
|
53 | 56 | ...
|
| 57 | + |
| 58 | + def aggregate(self, *aggregation: Aggregation) -> DataFrame: |
| 59 | + """ |
| 60 | + Aggregate columns according to given aggregation function. |
| 61 | +
|
| 62 | + Examples |
| 63 | + -------- |
| 64 | + >>> df: DataFrame |
| 65 | + >>> namespace = df.__dataframe_namespace__() |
| 66 | + >>> df.group_by('year').aggregate( |
| 67 | + ... namespace.Aggregation.sum('l_quantity').rename('sum_qty'), |
| 68 | + ... namespace.Aggregation.mean('l_quantity').rename('avg_qty'), |
| 69 | + ... namespace.Aggregation.mean('l_extended_price').rename('avg_price'), |
| 70 | + ... namespace.Aggregation.mean('l_discount').rename('avg_disc'), |
| 71 | + ... namespace.Aggregation.size().rename('count_order'), |
| 72 | + ... ) |
| 73 | + """ |
| 74 | + ... |
| 75 | + |
| 76 | +class Aggregation(Protocol): |
| 77 | + def rename(self, name: str) -> Aggregation: |
| 78 | + """ |
| 79 | + Assign given name to output of aggregation. |
| 80 | +
|
| 81 | + If not called, the column's name will be used as the output name. |
| 82 | + """ |
| 83 | + ... |
| 84 | + |
| 85 | + @classmethod |
| 86 | + def any(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 87 | + ... |
| 88 | + |
| 89 | + @classmethod |
| 90 | + def all(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 91 | + ... |
| 92 | + |
| 93 | + @classmethod |
| 94 | + def min(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 95 | + ... |
| 96 | + |
| 97 | + @classmethod |
| 98 | + def max(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 99 | + ... |
| 100 | + |
| 101 | + @classmethod |
| 102 | + def sum(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 103 | + ... |
| 104 | + |
| 105 | + @classmethod |
| 106 | + def prod(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 107 | + ... |
| 108 | + |
| 109 | + @classmethod |
| 110 | + def median(cls, column: str, *, skip_nulls: bool = True) -> Aggregation: |
| 111 | + ... |
| 112 | + |
| 113 | + @classmethod |
| 114 | + def mean(cls, column: str, *, skip_nulls: bool=True) -> Aggregation: |
| 115 | + ... |
| 116 | + |
| 117 | + @classmethod |
| 118 | + def std(cls, column: str, *, correction: int|float=1, skip_nulls: bool=True) -> Aggregation: |
| 119 | + ... |
| 120 | + |
| 121 | + @classmethod |
| 122 | + def var(cls, column: str, *, correction: int|float=1, skip_nulls: bool=True) -> Aggregation: |
| 123 | + ... |
| 124 | + |
| 125 | + @classmethod |
| 126 | + def size(cls) -> Aggregation: |
| 127 | + ... |
| 128 | + |
0 commit comments