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] DataFrame.describe has incorrect results for top in categorical column #9825

Closed
Tracked by #9815
bdice opened this issue Dec 2, 2021 · 0 comments · Fixed by #9867
Closed
Tracked by #9815

[BUG] DataFrame.describe has incorrect results for top in categorical column #9825

bdice opened this issue Dec 2, 2021 · 0 comments · Fixed by #9867
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@bdice
Copy link
Contributor

bdice commented Dec 2, 2021

Describe the bug
DataFrame.describe gives results for top in a categorical column that don't match pandas. The categories each occur once in this example, so the "top" is somewhat arbitrary, but we should match pandas' behavior if possible.

Reproduction & Expected Behavior
This is a minimal reproduction. Note that cudf gives f as the "top", while pandas and the cudf docstrings (see full reproduction) indicate that d should be the "top".

>>> cudf.Series(["d", "e", "f"], dtype="category").describe()
count     3
unique    3
top       f
freq      1
dtype: object
>>> pd.Series(["d", "e", "f"], dtype="category").describe()
count     3
unique    3
top       d
freq      1
dtype: object

The full error reproduction follows. 4 of 21 doctests (#9815) from the DataFrame.describe docstring fail because of this error.

Click to expand full error output
File "/home/bdice/code/cudf/python/cudf/cudf/core/series.py", line 3456, in Series.describe
Failed example:
    df.describe(include='all')
Expected:
           categorical numeric object
    count            3     3.0      3
    unique           3    <NA>      3
    top              d    <NA>      a
    freq             1    <NA>      1
    mean          <NA>     2.0   <NA>
    std           <NA>     1.0   <NA>
    min           <NA>     1.0   <NA>
    25%           <NA>     1.5   <NA>
    50%           <NA>     2.0   <NA>
    75%           <NA>     2.5   <NA>
    max           <NA>     3.0   <NA>
Got:
           categorical numeric object
    count            3     3.0      3
    unique           3    <NA>      3
    top              f    <NA>      a
    freq             1    <NA>      1
    mean          <NA>     2.0   <NA>
    std           <NA>     1.0   <NA>
    min           <NA>     1.0   <NA>
    25%           <NA>     1.5   <NA>
    50%           <NA>     2.0   <NA>
    75%           <NA>     2.5   <NA>
    max           <NA>     3.0   <NA>
**********************************************************************
File "/home/bdice/code/cudf/python/cudf/cudf/core/series.py", line 3508, in Series.describe
Failed example:
    df.describe(include=['category'])
Expected:
           categorical
    count            3
    unique           3
    top              d
    freq             1
Got:
           categorical
    count            3
    unique           3
    top              f
    freq             1
**********************************************************************
File "/home/bdice/code/cudf/python/cudf/cudf/core/series.py", line 3517, in Series.describe
Failed example:
    df.describe(exclude=[np.number])
Expected:
           categorical object
    count            3      3
    unique           3      3
    top              d      a
    freq             1      1
Got:
           categorical object
    count            3      3
    unique           3      3
    top              f      a
    freq             1      1
**********************************************************************
File "/home/bdice/code/cudf/python/cudf/cudf/core/series.py", line 3526, in Series.describe
Failed example:
    df.describe(exclude=[object])
Expected:
           categorical numeric
    count            3     3.0
    unique           3    <NA>
    top              d    <NA>
    freq             1    <NA>
    mean          <NA>     2.0
    std           <NA>     1.0
    min           <NA>     1.0
    25%           <NA>     1.5
    50%           <NA>     2.0
    75%           <NA>     2.5
    max           <NA>     3.0
Got:
           categorical numeric
    count            3     3.0
    unique           3    <NA>
    top              f    <NA>
    freq             1    <NA>
    mean          <NA>     2.0
    std           <NA>     1.0
    min           <NA>     1.0
    25%           <NA>     1.5
    50%           <NA>     2.0
    75%           <NA>     2.5
    max           <NA>     3.0
**********************************************************************
@bdice bdice added bug Something isn't working Python Affects Python cuDF API. labels Dec 2, 2021
@bdice bdice mentioned this issue Dec 2, 2021
9 tasks
@isVoid isVoid self-assigned this Dec 2, 2021
rapids-bot bot pushed a commit that referenced this issue Dec 14, 2021
Closes #9825 

This PR fixes the bug that when there are ties with most frequent categories in categorical series, the order returned is undefined. We break the tie by sorting the category and take its top.

Also included in this PR: refactors `describe` to use a dictionary items to describe for better readability. And enables https://github.com/rapidsai/cudf/blob/024003ca444f9d1a8374a1133337419f22cc880a/python/cudf/cudf/tests/test_series.py#L405

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Bradley Dice (https://github.com/bdice)

URL: #9867
rapids-bot bot pushed a commit that referenced this issue Jan 15, 2022
This PR adds doctests and resolves #9513. Several issues were found by running doctests that have now been resolved:

- [x] #9821
- [x] #9822
- [x] #9823
- [x] #9824
- [x] #9825
- [x] #9826
- [x] #9827
- [x] #9828 (workaround by deleting doctests)
- [x] #9829

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #9815
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

Successfully merging a pull request may close this issue.

2 participants