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.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
assertpd.DataFrame().idxmax(axis=1).dtype.kind=='i'# Fails: O in pandas 2.0.1, f in 1.5.3assertpd.DataFrame().idxmax(axis=0).dtype.kind=='i'# Fails: O in pandas 2.0.1, f in 1.5.3assertpd.DataFrame([[0], [1]], index=pd.DatetimeIndex(['2010-01-01', '2010-01-02'])).idxmax(axis=0).dtype.kind=='M'# Works OKpd.DataFrame([[], []], index=pd.DatetimeIndex(['2010-01-01', '2010-01-02'])).idxmax(axis=0).dtype.kind=='M'# Fails: O in pandas 2.0.1, f in 1.5.3
Issue Description
When idxmax/idxmin creates the series, it should explictly specify the dtype rather than relying on the Series constructor figuring it out from the input data.
(Pandas 1.5.3 raises a FutureWarning on all the failing examples above saying "The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.")
Note this is a different issue than the related problem with Series reported in #33941.
Expected Behavior
Asserts above should pass
Installed Versions
INSTALLED VERSIONS
------------------
commit : 37ea63d
python : 3.11.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.18.0-348.20.1.el8_5.x86_64
Version : #1 SMP Thu Mar 10 20:59:28 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
Yes, having idxmax return a series of the same type as the index would be correct, current behaviour is a bug.
Want to do the PR? I don't think this one will be difficult.
topper-123
added
Algos
Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
and removed
Needs Triage
Issue that has not been reviewed by a pandas team member
labels
May 17, 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
Issue Description
When idxmax/idxmin creates the series, it should explictly specify the dtype rather than relying on the Series constructor figuring it out from the input data.
(Pandas 1.5.3 raises a FutureWarning on all the failing examples above saying "The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.")
Note this is a different issue than the related problem with Series reported in #33941.
Expected Behavior
Asserts above should pass
Installed Versions
pandas : 2.0.1
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.7.2
pip : 23.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.13.2
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: