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: tz-aware series with NaT raises exception on .to_numpy("datetime64") #59772

Open
3 tasks done
Ranfir opened this issue Sep 10, 2024 · 2 comments
Open
3 tasks done
Labels
Bug Timezones Timezone data dtype

Comments

@Ranfir
Copy link

Ranfir commented Sep 10, 2024

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
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 : d9cdd2e
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

@Ranfir Ranfir added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 10, 2024
@Ranfir Ranfir changed the title BUG: BUG: tz-aware series with NaT raises exception on .to_numpy("datetime64") Sep 10, 2024
@yuanx749
Copy link
Contributor

Specify "datetime64[ns]" instead of "datetime64" would work.

@rhshadrach
Copy link
Member

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!

@rhshadrach rhshadrach added Timezones Timezone data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants