-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.Series.mode fails (sometimes) as aggregation method on groupby object #41368
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
Comments
Hi @MarcoGorelli, I've updated the example. I can sympathize with not downloading my random files, I wasn't sure given the 1000 lines. I've put it behind another one of those |
Skipping the fallback logic reveals what looks like the actual error is:
I think the root cause here is the same as #38534. Regardless of that this error message isn't overly helpful - would be nice to report why there are no results with more details. |
An MRE would be
or
which gives a more informative but not a great user-facing error:
|
Thanks @mzeitlin11, I've included your MRE in the original post instead of my, ehm, rather non-minimal example. This basically makes this a duplicate of #38534, although I agree it would also be worthwhile to replace |
@Huite OK closing as duplicate then. It's probably better to track all discussion there. |
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
This popped up randomly for some of my dataframes, but only a few.
EDIT: Thanks to @mzeitlin11 below for a properly minimal example.
This results in a
ValueError: no results
:other methods seem to work okay:
Oddly enough, slightly changing the selection makes it run:
scipy.stats.mode
also works fine:Problem description
I don't understand why it seems to randomly fail, there are no oddities with the data as far as I can tell.
Given the difference the selections make, I guess it's related with the specific number of occurences, which would suggest something internally in implementation of pd.Series.mode.
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.8.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Dutch_Netherlands.1252
pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.1
setuptools : 49.6.0.post20210108
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : 3.5.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.23.1
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : 2021.04.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : 0.18.0
xlrd : None
xlwt : None
numba : 0.52.0
The text was updated successfully, but these errors were encountered: