Skip to content

BUG: pandas.to_datetime("2023-01-01T15:58:12+09:00", format="%Y-%m-%dT%H:%M:%S.%f%z") has ValueError #53016

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

Closed
2 of 3 tasks
yuji38kwmt opened this issue May 1, 2023 · 1 comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@yuji38kwmt
Copy link

yuji38kwmt commented May 1, 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

In [57]: import pandas
In [58]: pandas.to_datetime("2023-01-01T15:58:12+09:00", format="%Y-%m-%dT%H:%M:%S.%f%z")
---------------------------------------------------------------------------

ValueError: time data "2023-01-01T15:58:12+09:00" doesn't match format "%Y-%m-%dT%H:%M:%S.%f%z", at position 0. You might want to try:
    - passing `format` if your strings have a consistent format;
    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.

Issue Description

The above code had ValueError in pandas 2.0.1. But in pandas 1.5.3, the above code had not error.

The above code raised a ValueError in pandas 2.0.1. However, there were no errors in the same code when run with pandas 1.5.3.

Expected Behavior

I expect the above code to not have any errors.

Installed Versions

INSTALLED VERSIONS

commit : 37ea63d
python : 3.11.2.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-70-generic
Version : #77-Ubuntu SMP Tue Mar 21 14:02:37 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : ja_JP.UTF-8
LOCALE : ja_JP.UTF-8

pandas : 2.0.1
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 23.0.1
Cython : None
pytest : 7.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.11.0
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 : 11.0.0
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

@yuji38kwmt yuji38kwmt added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 1, 2023
@MarcoGorelli
Copy link
Member

MarcoGorelli commented May 1, 2023

thanks for the report

the datetime string you posted doesn't have subseconds (%f), but your format string does. it was wrong in 1.5.3 to parse this

closing for now then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants