Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.Series(pd.NaT).dt.tz_localize("UTC").to_numpy("datetime64")
> TypeError: 'float' object cannot be interpreted as an integer
Issue Description
tz-aware series with NaT
raises exception on .to_numpy("datetime64")
Expected Behavior
Expect same behavior as a tz-naive series, e.g.
pd.Series(pd.NaT).to_numpy("datetime64")
numpy.datetime64('NaT')
Installed Versions
INSTALLED VERSIONS
------------------
commit : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140
python : 3.11.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.0-29-cloud-amd64
Version : #1 SMP Debian 5.10.216-1 (2024-05-03)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.2
numpy : 1.26.4
pytz : 2022.7.1
dateutil : 2.9.0.post0
setuptools : 69.2.0
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.23.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.6.1
gcsfs : 2024.6.1
matplotlib : 3.9.0
numba : 0.58.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 14.0.2
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
Comment From: yuanx749
Specify "datetime64[ns]" instead of "datetime64" would work.
Comment From: rhshadrach
Thanks for the report and @yuanx749 for the work around. But it does seem to me that this should work without [ns]
as well. Further investigations and PRs to fix are welcome!
Comment From: tomasmacieira
take