Skip to content

REGR: Assertion error in 1.2.1 but not 1.0.5 with groupby, resample, min #39329

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

Closed
2 tasks done
mcarans opened this issue Jan 21, 2021 · 3 comments · Fixed by #39655
Closed
2 tasks done

REGR: Assertion error in 1.2.1 but not 1.0.5 with groupby, resample, min #39329

mcarans opened this issue Jan 21, 2021 · 3 comments · Fixed by #39655
Labels
Groupby Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@mcarans
Copy link

mcarans commented Jan 21, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd
from datetime import datetime
from math import nan

def dt(datestr):
    return datetime.strptime(datestr, '%Y-%m-%d')

df = pd.DataFrame(data={'Date_reported': {0: dt('2020-07-23'), 1: dt('2020-07-24'), 2: dt('2020-07-25'), 3: dt('2020-07-26'), 4: dt('2020-07-27'), 5: dt('2020-07-28'), 6: dt('2020-07-29'), 7: dt('2020-07-30'), 8: dt('2020-07-31'), 9: dt('2020-08-01'), 10: dt('2020-08-02'), 11: dt('2020-08-03'), 12: dt('2020-08-04'), 13: dt('2020-08-05'), 14: dt('2020-08-06'), 15: dt('2020-07-23'), 16: dt('2020-07-24'), 17: dt('2020-07-25'), 18: dt('2020-07-26'), 19: dt('2020-07-27'), 20: dt('2020-07-28'), 21: dt('2020-07-29'), 22: dt('2020-07-30'), 23: dt('2020-07-31'), 24: dt('2020-08-01'), 25: dt('2020-08-02'), 26: dt('2020-08-03'), 27: dt('2020-08-04'), 28: dt('2020-08-05'), 29: dt('2020-08-06')}, 'ISO_3_CODE': {0: 'AFG', 1: 'AFG', 2: 'AFG', 3: 'AFG', 4: 'AFG', 5: 'AFG', 6: 'AFG', 7: 'AFG', 8: 'AFG', 9: 'AFG', 10: 'AFG', 11: 'AFG', 12: 'AFG', 13: 'AFG', 14: 'AFG', 15: 'H63', 16: 'H63', 17: 'H63', 18: 'H63', 19: 'H63', 20: 'H63', 21: 'H63', 22: 'H63', 23: 'H63', 24: 'H63', 25: 'H63', 26: 'H63', 27: 'H63', 28: 'H63', 29: 'H63'}, 'Cumulative_cases': {0: 35915, 1: 35981, 2: 36036, 3: 36157, 4: 36263, 5: 36368, 6: 36471, 7: 36542, 8: 36542, 9: 36710, 10: 36710, 11: 36710, 12: 36747, 13: 36829, 14: 36896, 15: 47194, 16: 47856, 17: 48448, 18: 48952, 19: 49388, 20: 49825, 21: 50409, 22: 51000, 23: 51380, 24: 51942, 25: 52265, 26: 52490, 27: 52771, 28: 53457, 29: 53877}, 'Regional_office': {0: 'ROAP', 1: 'ROAP', 2: 'ROAP', 3: 'ROAP', 4: 'ROAP', 5: 'ROAP', 6: 'ROAP', 7: 'ROAP', 8: 'ROAP', 9: 'ROAP', 10: 'ROAP', 11: 'ROAP', 12: 'ROAP', 13: 'ROAP', 14: 'ROAP', 15: nan, 16: nan, 17: nan, 18: nan, 19: nan, 20: nan, 21: nan, 22: nan, 23: nan, 24: nan, 25: nan, 26: nan, 27: nan, 28: nan, 29: nan}})
result = df.groupby(['ISO_3_CODE']).resample('W', on='Date_reported').min()

Problem description

When running it in 1.21 it fails with:

    assert len(result._mgr.blocks) == 1
AssertionError

That exception is raised from another:

NotImplementedError: function is not implemented for this dtype: [how->min,dtype->object]

Expected Output

When running the above code in 1.05 it works without error.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9d598a5
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.8.0-40-generic
Version : #45~20.04.1-Ubuntu SMP Fri Jan 15 11:35:04 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_NZ.UTF-8
LOCALE : en_NZ.UTF-8
pandas : 1.2.1
numpy : 1.19.4
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.1.1
Cython : None
pytest : 6.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.22
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None

@mcarans mcarans added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 21, 2021
@jorisvandenbossche jorisvandenbossche added Groupby Regression Functionality that used to work in a prior pandas version and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 22, 2021
@jorisvandenbossche jorisvandenbossche added this to the 1.2.2 milestone Jan 22, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jan 22, 2021
@simonjayhawkins simonjayhawkins changed the title BUG: Assertion error in 1.2.1 but not 1.0.5 with groupby, resample, min REGR: Assertion error in 1.2.1 but not 1.0.5 with groupby, resample, min Jan 22, 2021
@simonjayhawkins
Copy link
Member

Thanks @mcarans for the report.

When running the above code in 1.05 it works without error.

first bad commit: [0e199f3] REF: simplify _cython_agg_blocks (#35841) cc @jbrockmendel

@colditzjb
Copy link

FWIW, I updated to pandas=1.2.3 today and am still having errors with df.groupby([...]).max()

I rolled back to a legacy version (pandas=0.24.1) that I wrote my original code with, and the issues disappeared. Here's the last error block in version 1.2.3:

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/groupby/generic.py in py_fallback(bvalues)
1079 result = result._consolidate()
1080 assert isinstance(result, (Series, DataFrame)) # for mypy
-> 1081 assert len(result._mgr.blocks) == 1

When I looked at my groupby() dataframe, it wasn't actually grouped and df.head(x) produced a full dataframe output (not a head). Nonetheless, the .max() aggregator seemed to correctly resolve it in pandas=0.24.1 but not in the current version. If there is an ongoing issue here, I think it may be related to df.groupby() being too permissive about data fidelity... it's passing weird data to the aggregator extensions. The underlying issue is probably groupby() allowing messy data input and passing it to aggregator handlers in unexpected ways.

Sorry that I don't have data to share or bandwidth to open a new issue at the moment. Just be aware that groupby() has weird behavior and that these aggregation errors are likely a side effect of that. I hope this helps somehow, anyway.

@simonjayhawkins
Copy link
Member

Sorry that I don't have data to share or bandwidth to open a new issue at the moment. Just be aware that groupby() has weird behavior and that these aggregation errors are likely a side effect of that. I hope this helps somehow, anyway.

Thanks for the comment. If you get a chance to open a new issue at some point with a reproducible code sample then there is a greater chance that someone will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants