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: pd.Series idxmax raises ValueError instead of returning <NA> when all values are <NA> #51276

Closed
2 of 3 tasks
hchau630 opened this issue Feb 9, 2023 · 2 comments · Fixed by #54226
Closed
2 of 3 tasks
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@hchau630
Copy link

hchau630 commented Feb 9, 2023

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

s = pd.Series([np.nan, np.nan]).convert_dtypes()
s.idxmax(skipna=True)

Issue Description

According to documentation, when pd.Series contains all NaN values, calling idxmax with skipna=True should return NaN. However, in this case it raise "ValueError: attempt to get argmax of an empty sequence" instead. This issue only happens when I used convert_dtypes() on the Series before calling idxmax. Interestingly, the same issue does not appear for pd.DataFrame.

Expected Behavior

Should return or NaN rather than raising ValueError.

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.9.13.final.0
python-bits : 64
OS : Darwin
OS-release : 21.3.0
Version : Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.23.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.2.2
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@hchau630 hchau630 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 9, 2023
@rhshadrach rhshadrach added Numeric Operations Arithmetic, Comparison, and Logical operations 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 labels Feb 11, 2023
@rhshadrach
Copy link
Member

Thanks for the report! Confirmed on main; further investigations and PRs to fix are welcome.

@jbrockmendel
Copy link
Member

Discussed in in last week's dev call, agreed that raising is the preferred eventual behavior, need a deprecation cycle to get consistent behavior across dtypes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
3 participants