Skip to content

Dataframe groupby()[column].agg fails with AttributeError #3438

Closed

Description

@joergdietrich

Minimal not working example (dask 0.17.2, pandas 0.22.0, Python 3.6):

import pandas as pd
from dask import dataframe as dd

df = pd.DataFrame({'A': [1, 2, 3, 1, 2, 3, 1, 2, 4],
        'B': [-0.776, -0.4, -0.873,  0.054,  1.419, -0.948, -0.967, -1.714,
              -0.666]})
ddf = dd.from_pandas(df, npartitions=1)
ddf.groupby('A')['B'].agg('var')
AttributeError                            Traceback (most recent call last)
<ipython-input-1-b43466d1ae6a> in <module>()
      6               -0.666]})
      7 ddf = dd.from_pandas(df, npartitions=1)
----> 8 ddf.groupby('A')['B'].agg('var')
      9 
     10 

~/applications/anaconda3/lib/python3.6/site-packages/dask/dataframe/groupby.py in agg(self, arg, split_every, split_out)
   1217     @derived_from(pd.core.groupby.SeriesGroupBy)
   1218     def agg(self, arg, split_every=None, split_out=1):
-> 1219         return self.aggregate(arg, split_every=split_every, split_out=split_out)

~/applications/anaconda3/lib/python3.6/site-packages/dask/dataframe/groupby.py in aggregate(self, arg, split_every, split_out)
   1211 
   1212         if not isinstance(arg, (list, dict)):
-> 1213             result = result[result.columns[0]]
   1214 
   1215         return result

AttributeError: 'Series' object has no attribute 'columns'

Activity

  1. mrocklin commented on Apr 25, 2018

    @mrocklin
    Member

    Confirmed. Thank you for the excellent bug report @joergdietrich .

    The solution to this seems straightforward; we should only do this transformation when the result object is a DataFrame rather than a Series. Do you have any interest in submitting this as a pull request? Most of the work is already done with your excellent test case above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions