Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Single column slicing with loc returns a DataFrame not a Series #1513

Closed
beckernick opened this issue Apr 27, 2019 · 2 comments
Closed
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@beckernick
Copy link
Member

Describe the bug
Single column slicing with loc returns a DataFrame not a Series.

Steps/Code to reproduce bug

import cudf
import pandas as pd

pdf = pd.DataFrame({'x': [1, 2, 3, 4, 5, 6, 7, 8]})
gdf = cudf.from_pandas(pdf)
print(type(pdf.loc[0:1, 'x']))
print(type(gdf.loc[0:1, 'x']))
<class 'pandas.core.series.Series'>
<class 'cudf.dataframe.dataframe.DataFrame'>

Expected behavior
I expect this to be consistent with pandas and return a Series, not a DataFrame.

Additional context
This bug partially blocks cumulative aggregation operations with dask-cudf.

@beckernick beckernick added bug Something isn't working Needs Triage Need team to review and classify Python Affects Python cuDF API. and removed Needs Triage Need team to review and classify labels Apr 27, 2019
@beckernick
Copy link
Member Author

beckernick commented Apr 27, 2019

This is the line of code. We only create a Series if the row_label is not None, which only occurs rather than also if a slice occurs. Our return type should probably not based on whether we take a single row or a slice of rows, but based on the two-way interaction of row and column indexing. Something like:

  1. single row + single column -> scalar
  2. single row + multiple columns -> series
  3. slice + single column -> series
  4. slice + multiple columns -> dataframe

Pandas actually doesn't quite do this exclusively. They also return a dataframe for slice + list of a single column. So if the row indexer is a slice and the column indexer is a list we can return a dataframe.

type(pdf.loc[0:1, ['x']])
pandas.core.frame.DataFrame

They also return a series for a single row + list of single column:

type(pdf.loc[0, ['x']])
pandas.core.series.Series

So essentially, they "upcast" from scalar -> and series -> dataframe if the column indexer argument is a list for the respective row indexer (single row and slice).

@beckernick
Copy link
Member Author

Resolved by #1622.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Affects Python cuDF API.
Projects
None yet
Development

No branches or pull requests

2 participants