You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
importpandasaspd# pandas==1.0.4, but this issue exists since 1.0.0importnumpyasnp# numpy==1.16.3toy_df=pd.DataFrame(
{
'group': np.random.randint(0, 5, 10),
'value': np.random.random(10)
},
index=np.random.random(10),
)
# fails with floating point indextoy_df.groupby('group').apply(sum)
toy_df.groupby('group').apply(lambdax: x['value'].sum())
# with integer index then it works:toy_df.index=np.random.randint(0, 5, 10)
toy_df.groupby('group').apply(lambdax: x['value'].sum())
toy_df.groupby('group').apply(sum)
Problem description
[this should explain why the current behaviour is a problem and why the expected output is a better solution]
I found this peculiar issue with the new version of pandas. When I have floating point index in a pandas DataFrame, then I cannot perform any groupby.apply operation on it. It will always give the below error:
after this line, sdata still does not have a sorted index, and then the next line raises the ValueError: index must be monotonic increasing or decreasing.
I tested that this error exists in pandas==1.0.4 and pandas==1.0.0 but does not exist in pandas==0.25.1.
Expected Output
Expected output from groupby apply should be the same in the example with either floating point index or integer index.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.0.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.173-137.229.amzn2.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
[this should explain why the current behaviour is a problem and why the expected output is a better solution]
I found this peculiar issue with the new version of pandas. When I have floating point index in a pandas DataFrame, then I cannot perform any
groupby.apply
operation on it. It will always give the below error:When I used
ipdb
to trace inside the error, I found that the following line caused the problem:after this line,
sdata
still does not have a sorted index, and then the next line raises theValueError: index must be monotonic increasing or decreasing
.I tested that this error exists in
pandas==1.0.4
andpandas==1.0.0
but does not exist inpandas==0.25.1
.Expected Output
Expected output from groupby apply should be the same in the example with either floating point index or integer index.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.0.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.173-137.229.amzn2.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.4
numpy : 1.16.3
pytz : 2020.1
dateutil : 2.8.0
pip : 20.0.2
setuptools : 47.1.1.post20200604
Cython : 0.29.2
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pytest : None
pyxlsb : None
s3fs : 0.4.0
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: