Skip to content

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

Closed
@tamargrey

Description

@tamargrey
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.RegressionFunctionality that used to work in a prior pandas versionquantilequantile method

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions