-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: FutureWarning for pandas datetime dtype series strftime with all NA values #45858
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
Thanks @JeremyVriens for the report
deprecation added in #42870 |
IIUC in a future version this will return with object dtype, which seems More Correct to me. So might want to catch this warning and then re-issue with something more specific? |
moving to 1.4.2 |
Why will this return an object dtype in a future version? No warning is raised when there're non-NA values in the datetime64[ns] series ( |
Because object-dtype is what we get in every other case with strftime. float64 doesn't make sense as a strftime result.
|
moving to 1.4.3 |
moving to 1.4.4 |
Agreed that this returning float64 dtype for all-NaN is a bug. The result dtype shouldn't depend on the values. I think the root bug is that In [32]: pd.DatetimeIndex([pd.NaT]).strftime("%Y")
/home/taugspurger/miniconda3/envs/pandas=1.4.2/lib/python3.10/site-packages/pandas/core/indexes/extension.py:101: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
return Index(result, name=self.name)
Out[32]: Float64Index([nan], dtype='float64') If that were fixed I think the series case will automatically be fixed too. |
The underlying
but indeed then passing this to |
hey there, thanks for this! so pandas>=1.4.0 is a dependency in my software package (pysyd) and I've had people reach out to me due to this error. is there a quick hack that I can do from my end or will I/they have to wait until the full v1.4.4 release? |
I am receiving this warning performing a pivot of a table (it will include some date/time data) Will the warning become an error in the future? Is there anything that users need to do as a work-around or will this issue be resolved in an upcoming release? (I have upgraded to 1.5.2 and still receive the warning). Many thanks |
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
Since Pandas 1.4.0 a warning is raised:
FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
This warning is raised when all values in the series are N/A (even though the dtype of the series is correct).
Note: the warning is not raised when one of the values in the series is not NA
Expected Behavior
No FutureWarning should be raised.
Installed Versions
INSTALLED VERSIONS
commit : bb1f651
python : 3.9.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.4.0
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 59.2.0
Cython : None
pytest : 7.0.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.31
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: