Skip to content

Groupby-agg on index with known divisions results in unknown divisions #2999

Open

Description

@michcio1234

I would expect ddf.groupby(ddf.index).sum() to have same divisions as ddf, but they seem to be unknown. Not sure if this is a desired behaviour or if I'm doing something wrong.

In[2]: import pandas as pd
In[3]: import dask.dataframe as dd
In[4]: ddf = dd.from_pandas(pd.DataFrame({'A': [1, 2]}), npartitions=1)
In[5]: ddf.divisions
Out[5]: (0, 1)
In[6]: ddf.groupby(ddf.index).sum().divisions
Out[6]: (None, None)
  • dask 0.16
  • pandas 0.21.1

Activity

  1. michcio1234 commented on Dec 15, 2017

    @michcio1234
    Author

    After taking a look at dask tests I discovered what follows:

    In[2]: import dask
      ...: import dask.dataframe as dd
      ...: import pandas as pd
      ...: import numpy as np
    
    In[3]: ddf = dd.from_pandas(pd.DataFrame({'A': [1, 2]}, index=pd.Series([0, 1], name='idx')), npartitions=1)
    
    In[4]: ddf.divisions
    Out[4]: (0, 1)
    
    In[5]: ddf.groupby(ddf.index).sum().divisions
    Out[5]: (None, None)
    
    In[6]: ddf.groupby('idx').sum().divisions
    Out[6]: (None, None)
    
    In[7]: ddf.groupby(ddf.index).apply(np.sum).divisions
    UserWarning: `meta` is not specified...
    Out[7]: (None, None)
    
    In[8]: ddf.groupby('idx').apply(np.sum).divisions
    UserWarning: `meta` is not specified...
    Out[8]: (0, 1)

    (warnings were truncated)

    So, the expected behaviour occurs only when

    1. I pass index name instead of the index itself to a groupby method AND
    2. I use .apply(np.sum) instead of .sum() as an aggregation (works with built-in sum too)
  2. mrocklin commented on Dec 16, 2017

    @mrocklin
    Member
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions