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

groupby.quantile() fails on Timedelta columns #29485

Closed
dokteurwho opened this issue Nov 8, 2019 · 2 comments · Fixed by #37145
Closed

groupby.quantile() fails on Timedelta columns #29485

dokteurwho opened this issue Nov 8, 2019 · 2 comments · Fixed by #37145
Labels
Bug Groupby quantile quantile method Resample resample method Timedelta Timedelta data type
Milestone

Comments

@dokteurwho
Copy link

Code Sample, groupby quantile example

# groupby quantile example
import pandas as pd

print(f"Pandas {pd.__version__}")

df = pd.DataFrame({
    'idx': [1, 1, 2],
    'start_date': ['2019-10-02', '2019-10-04', '2019-10-05'],
    'arrival_date': ['2019-11-02', '2019-10-14', '2019-10-15']})

for c in ['start_date', 'arrival_date']:
    df[c] = pd.to_datetime(df[c])

df['delta'] = df['arrival_date'] - df['start_date']

print(df.groupby('idx')[['delta']].quantile(.9))

Problem description

The code example used to work in 0.21.1.
In 0.25 I obtain a "TypeError: No matching signature found"

Expected Output

Pandas 0.21.1

           delta

idx
1 28 days 21:36:00
2 10 days 00:00:00

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-693.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.3
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.1
pip : 18.1
setuptools : 40.8.0.post20191016
Cython : 0.29.14
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
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@WillAyd
Copy link
Member

WillAyd commented Nov 8, 2019

The method was overhauled in 0.25 to push it down from the Python space to C. If you want to poke around the implementation is in pandas.core.groupby.groupby

@jreback
Copy link
Contributor

jreback commented Jul 22, 2020

a related version (different error on master)

In [8]: x = pd.DataFrame({'time': pd.date_range('20200101', periods=10, tz='UTC'), 'value': pd.to_timedelta(np.arange(10), unit='s')}).set_index('time')             

In [9]: x                                                                                                                                                            
Out[9]: 
                                    value
time                                     
2020-01-01 00:00:00+00:00 0 days 00:00:00
2020-01-02 00:00:00+00:00 0 days 00:00:01
2020-01-03 00:00:00+00:00 0 days 00:00:02
2020-01-04 00:00:00+00:00 0 days 00:00:03
2020-01-05 00:00:00+00:00 0 days 00:00:04
2020-01-06 00:00:00+00:00 0 days 00:00:05
2020-01-07 00:00:00+00:00 0 days 00:00:06
2020-01-08 00:00:00+00:00 0 days 00:00:07
2020-01-09 00:00:00+00:00 0 days 00:00:08
2020-01-10 00:00:00+00:00 0 days 00:00:09

In [10]: x.resample('2D').quantile(0.99)                                                                                                                             
TypeError: Cannot cast TimedeltaArray to dtype float64

@jreback jreback added this to the Contributions Welcome milestone Jul 22, 2020
@jreback jreback added the Resample resample method label Jul 22, 2020
@jreback jreback modified the milestones: Contributions Welcome, 1.2 Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby quantile quantile method Resample resample method Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants