Open cmdlineluser opened 11 months ago
https://github.com/pola-rs/polars/blob/main/py-polars/polars/dataframe/group_by.py
"just" needs this treatment
Yeah, the machinery is there I think.
_current_index
is created inside __iter__
So it works if you manually call iter()
df = pl.DataFrame({"a": [1, 1, 2], "b": [3, 4, 5]})
next(iter(df.group_by("a")))
# (1,
# shape: (2, 2)
# ┌─────┬─────┐
# │ a ┆ b │
# │ --- ┆ --- │
# │ i64 ┆ i64 │
# ╞═════╪═════╡
# │ 1 ┆ 3 │
# │ 1 ┆ 4 │
# └─────┴─────┘)
I think it needs to be in __init__
or else if in __next__
it needs to see if it exists and if not create it
I can try to fix it
This should raise a TypeError.
Instead of the try-except proposed, we should return an object of a new class GroupIter
on __iter__
. Then it is solved by the type system.
Checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of Polars.
Reproducible example
Log output
No response
Issue description
Not sure if
next()
is intended to work or not, it seems like it should raise a TypeError instead if it isn't.Expected behavior
"Work" or return a TypeError?
Installed versions