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: Cannot calculate quantiles from Int64Dtype Series when results are floats #42626

Closed
2 of 3 tasks
tamargrey opened this issue Jul 20, 2021 · 2 comments · Fixed by #42936
Closed
2 of 3 tasks

BUG: Cannot calculate quantiles from Int64Dtype Series when results are floats #42626

tamargrey opened this issue Jul 20, 2021 · 2 comments · Fixed by #42936
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. quantile quantile method Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@tamargrey
Copy link

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

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

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import pandas as pd

pd.Series([1, 2, 3], dtype="Int64").quantile([0.75])

The result of the above quantile call should be 2.5, and the following error is thrown any time the result of the quantile call is a float: TypeError: cannot safely cast non-equivalent object to int64. Below, when we only calculate the 0.5 quantile (which is 2), no error is thrown:

pd.Series([1, 2, 3], dtype="Int64").quantile([0.5])

Problem description

In 1.2.5, this call works for Int64Dtype with the resulting dtype being object, and in 1.3.0, this call works for the non nullable int64 with dtype float64.

Expected Output

If we want to go with the 1.2.5 output, the expected output would be to not error and result in a Series with dtype object. It could also make sense for the resulting series to have float64 dtype.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f00ed8f
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.0
numpy : 1.21.0
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 41.2.0
Cython : None
pytest : 6.0.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.7
fastparquet : 0.5.0
gcsfs : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1

@tamargrey tamargrey added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 20, 2021
@thosangs
Copy link

Can i take this one ?

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jul 22, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3.1 milestone Jul 22, 2021
@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version quantile quantile method ExtensionArray Extending pandas with custom dtypes or arrays. NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Jul 22, 2021
@simonjayhawkins
Copy link
Member

Thanks @tamargrey for the report

In 1.2.5, this call works for Int64Dtype with the resulting dtype being object

first bad commit: [0a88eaa] BUG: quantile for ExtensionArray (#39606) cc @jbrockmendel

If we want to go with the 1.2.5 output, the expected output would be to not error and result in a Series with dtype object.

Also now errors with pd.Series([1, 2, 3], dtype="Int64").quantile(0.75) where the expected output (and output in 1.2.5) is a Python float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. quantile quantile method Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants