BUG: Cannot convert pd.NA to Timestamp · Issue #45481 · pandas-dev/pandas (original) (raw)
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
print(f"{pd.version=}") for v in [None, np.nan, pd.NA]: print(v, pd.Timestamp(v), sep="\t")
Issue Description
pd.Timestamp
constructor fails to handle pd.NA
properly on the latest version and main branch (1.5.0.dev0+128.g91d3f0b246
).
This works fine (on both main branch and 1.3.5) using pd.to_datetime
(seems to have been fixed in #32213):
In [5]: pd.to_datetime([np.nan, None, pd.NA]) Out[5]: DatetimeIndex(['NaT', 'NaT', 'NaT'], dtype='datetime64[ns]', freq=None)
Expected Behavior
I expect the Timestamp
constructor to handle pd.NA
the same way as it handles None
and np.nan
, i.e. pd.Timestamp(pd.NA)
should return NaT
.
Installed Versions
INSTALLED VERSIONS
------------------
commit : 91d3f0b2467e045523358b493789b73b405967e9
python : 3.10.0.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-18362-Microsoft
Version : #1049-Microsoft Thu Aug 14 12:01:00 PST 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.0.dev0+128.g91d3f0b246
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.25
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.29.0
pandas_datareader: None
bs4 : None
bottleneck : 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
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None