Skip to content

TypeError when calculating min/max of period column using groupby #31471

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
fajost opened this issue Jan 30, 2020 · 1 comment · Fixed by #31477
Closed

TypeError when calculating min/max of period column using groupby #31471

fajost opened this issue Jan 30, 2020 · 1 comment · Fixed by #31477
Labels
Groupby Period Period data type Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@fajost
Copy link

fajost commented Jan 30, 2020

Code Sample, a copy-pastable example if possible

import pandas as pd
periods = pd.period_range(start="2019-01", periods=4, freq="M")
groups = [1, 1, 2, 2]
df = pd.DataFrame({"periods": periods, "groups": groups})
result = df.groupby("groups")["periods"].min()

Problem description

The last line of the example throws a TypeError: data type not understood.

Traceback (most recent call last): File "test.py", line 6, in result = df.groupby("groups")["periods"].min() File "...\site-packages\pandas\core\groupby\groupby.py", line 1378, in f return self._cython_agg_general(alias, alt=npfunc, **kwargs) File "...\site-packages\pandas\core\groupby\groupby.py", line 889, in _cython_agg_general result, agg_names = self.grouper.aggregate( File "...\site-packages\pandas\core\groupby\ops.py", line 580, in aggregate return self._cython_operation( File "...\site-packages\pandas\core\groupby\ops.py", line 573, in _cython_operation result = result.astype(orig_values.dtype) TypeError: data type not understood

Expected Output

The result DataFrame should contain the earliest period (in this case 2019-01) for each grouping slice.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United Kingdom.1252

pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200127
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@jreback jreback added Bug Groupby Period Period data type labels Jan 31, 2020
@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version and removed Bug labels Jan 31, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.0.1 milestone Jan 31, 2020
@jorisvandenbossche
Copy link
Member

@fajost Thanks for the report!

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

Successfully merging a pull request may close this issue.

4 participants