Skip to content

groupby.quantile(<arraylike>) fails with AssertionError #30289

Closed
@ketzu

Description

@ketzu

Code Sample, a copy-pastable example if possible

# Your code here
df = pd.DataFrame(np.array([10*[_%4] for _ in range(100)]))            

df.groupby(0).quantile(0.5)                                            
# Out[19]: 
#     1    2    3    4    5    6    7    8    9
# 0                                             
# 0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
# 1  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
# 2  2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0
# 3  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0

df.groupby(0).quantile([0.5,0.99])                                     
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-20-21c92d2481c9> in <module>
----> 1 df.groupby(0).quantile([0.5,0.99])

~/PycharmProjects/netsim_stats/venv/lib/python3.7/site-packages/pandas/core/groupby/groupby.py in quantile(self, q, interpolation)
   1950 
   1951             indices = np.concatenate(arrays)
-> 1952             assert len(indices) == len(result)
   1953             return result.take(indices)
   1954 

AssertionError: 

df.quantile([0.5,0.99])                                                
#        0    1    2    3    4    5    6    7    8    9
# 0.50  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5
# 0.99  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0
                                                              
df.groupby(0)[1].quantile(0.5) 
# 0
# 0    0.0
# 1    1.0
# 2    2.0
# 3    3.0
# Name: 1, dtype: float64

df.groupby(0)[1].quantile([0.5,0.99])

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-24-ebf6ade716ff> in <module>
----> 1 df.groupby(0)[1].quantile([0.5,0.99])

~/PycharmProjects/netsim_stats/venv/lib/python3.7/site-packages/pandas/core/groupby/groupby.py in quantile(self, q, interpolation)
   1950 
   1951             indices = np.concatenate(arrays)
-> 1952             assert len(indices) == len(result)
   1953             return result.take(indices)
   1954 

AssertionError: 

Problem description

The above is a constructed minimal example.
I am not sure how much I should elaborate on the "why this is a problem".

groupby.quantile() fails with an assertion error for "larger" dataframes, smaller dataframes seem to work fine.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.15-200.fc30.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 0.25.3
numpy : 1.17.4
pytz : 2019.3
dateutil : 2.8.1
pip : 19.1.1
setuptools : 40.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.2.5
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.2.0
pandas_datareader: None
bs4 : 4.6.3
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.2.5
matplotlib : 3.1.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.1.0
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions