dask / dask/dask

Cumulative aggregation on SeriesGroupBy produces TypeError: assign() keywords must be strings

Open
#9,512 1 comment 0 reactions 0 assignees View on GitHub
bug dataframe needs attention
Dominant language
Python
Stars
13.9k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

**What happened**:
Received the following stack trace when trying to do a cumulative aggregation on a `SeriesGroupBy` (e.g., `cumsum`, `cumprod`) in Dask. The same code runs in pandas without error. Other aggregations (e.g., `sum`, `prod`, `max`) seem to work without error in Dask.
```
Traceback (most recent call last):
File "", line 1, in
File "/Users/kevfly/.pyenv/versions/3.8.9/lib/python3.8/site-packages/dask/dataframe/groupby.py", line 1461, in cumsum
return self._cum_agg("cumsum", chunk=M.cumsum, aggregate=M.add, initial=0)
File "/Users/kevfly/.pyenv/versions/3.8.9/lib/python3.8/site-packages/dask/dataframe/groupby.py", line 1337, in _cum_agg
cumpart_ext = cumpart_raw_frame.assign(
TypeError: assign() keywords must be strings
```

**What you expected to happen**:
Return a `Series` with the cumulative aggregation.

**Minimal Complete Verifiable Example**:

```
import pandas as pd
pdf = pd.DataFrame({'index': ['A', 'A', 'B'], 'start': [0,0,0], 'end': [10,10,10]})
pds = (
pdf['start'] > pdf.groupby('index', sort=False)['end'].shift().cummax()
).groupby(pdf['index'], sort=False).cumsum()

import dask.dataframe as dd
ddf = dd.from_pandas(pdf, npartitions=1)
ddf = ddf.reset_index()
dds = (
ddf['start'] > ddf.groupby('index', sort=False)['end'].shift(meta=('end', 'int64')).cummax()
).groupby(ddf['index'], sort=False).cumsum()
```

**Anything else we need to know?**:
This may be related to this [issue](https://github.com/dask/dask/issues/4922), but I don't know the equivalent workaround if there is one.

**Environment**:

- Dask version: 2022.9.1
- Python version: 3.8.9
- Operating System: MacOS
- Install method: pip

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.