Skip to content

Commit

Permalink
deprecate index access in groupby
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 11, 2022
1 parent f800a64 commit c05168d
Showing 1 changed file with 3 additions and 34 deletions.
37 changes: 3 additions & 34 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4199,6 +4199,9 @@ def _select(self, columns: Union[str, List[str]]) -> "GBSelection":
columns
One or multiple columns.
"""
print(
"accessing GroupBy by index is deprecated, consider using the `.agg` method"
)
if isinstance(columns, str):
columns = [columns]
return GBSelection(self._df, self.by, columns)
Expand Down Expand Up @@ -4290,18 +4293,6 @@ def agg(
column_to_agg
map column to aggregation functions.
Use lazy API syntax (recommended)
>>> [pl.col("foo").sum(), pl.col("bar").min()] # doctest: +SKIP
>>> [
... ("foo", ["sum", "n_unique", "min"]),
... ("bar", ["max"]),
... ] # doctest: +SKIP
Column name to aggregation with dict:
>>> {"foo": ["sum", "n_unique", "min"], "bar": "max"} # doctest: +SKIP
Returns
-------
Result of groupby split apply operations.
Expand All @@ -4310,35 +4301,13 @@ def agg(
Examples
--------
Use lazy API:
>>> df.groupby(["foo", "bar"]).agg(
... [
... pl.sum("ham"),
... pl.col("spam").tail(4).sum(),
... ]
... ) # doctest: +SKIP
Use a dict:
>>> df.groupby(["foo", "bar"]).agg(
... {
... "spam": ["sum", "min"],
... }
... ) # doctest: +SKIP
shape: (3, 2)
┌─────┬─────┐
│ foo ┆ bar │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════╪═════╡
│ a ┆ 1 │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ a ┆ 2 │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ b ┆ 3 │
└─────┴─────┘
"""

# a single list comprehension would be cleaner, but mypy complains on different
Expand Down

0 comments on commit c05168d

Please sign in to comment.