Skip to content

cumsum() doesn't work on tables with >1 partition #5024

Closed

Description

@tshatrov

I can't make cumsum work on dask dataframes with more than 1 partition.

import dask
ts = dask.datasets.timeseries()
tts = ts.loc[:, ['x', 'y']]
tts.cumsum().compute() # results in error TypeError: cannot do slice indexing ...

tts.compute().cumsum() # works
ttts = tts.repartition(npartitions=1)
ttts.cumsum().compute() # also works

dask.__version__ is 1.2.2.

Activity

  1. TomAugspurger commented on Jun 28, 2019

    @TomAugspurger
    Member

    What happens if you compute directly after the loc?

  2. tshatrov commented on Jun 28, 2019

    @tshatrov
    ContributorAuthor

    Compute after the loc works (5th line in the original example). It creates a normal pandas dataframe and cumsum works on it.

  3. TomAugspurger commented on Jun 28, 2019

    @TomAugspurger
    Member

    This is a bug in dask.dataframe.DataFrame.take_last

    dask/dask/dataframe/core.py

    Lines 5238 to 5240 in e0f9456

    if is_dataframe_like(a):
    # create Series from appropriate backend dataframe library
    series_typ = type(a.loc[0:1, a.columns[0]])

    That should be a.iloc[0:1, 0] I think.

  4. TomAugspurger commented on Jun 28, 2019

    @TomAugspurger
    Member

    With

    diff --git a/dask/dataframe/core.py b/dask/dataframe/core.py
    index c7eda18ca..887075f06 100644
    --- a/dask/dataframe/core.py
    +++ b/dask/dataframe/core.py
    @@ -5237,7 +5237,7 @@ def _take_last(a, skipna=True):
             # in each column
             if is_dataframe_like(a):
                 # create Series from appropriate backend dataframe library
    -            series_typ = type(a.loc[0:1, a.columns[0]])
    +            series_typ = type(a.iloc[0:1, 0])
                 if a.empty:
                     return series_typ([])
                 return series_typ(

    things work fine (thanks for the nice example).

    Are you interested in making a pull request with that change, and a test to go with it @tshatrov?

  5. tshatrov commented on Jul 1, 2019

    @tshatrov
    ContributorAuthor

    Done #5034

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