Skip to content

BUG: to_datetime with specific format are incorrectly matching #48707

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
3 tasks done
dadiego91 opened this issue Sep 22, 2022 · 4 comments
Closed
3 tasks done

BUG: to_datetime with specific format are incorrectly matching #48707

dadiego91 opened this issue Sep 22, 2022 · 4 comments
Labels
Bug Datetime Datetime data dtype

Comments

@dadiego91
Copy link

dadiego91 commented Sep 22, 2022

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

ser = pd.Series(["2022\\12\\25"])

pd.to_datetime(ser, format="%Y-%m-%d") # this should fail, because format does not match

Issue Description

There is an inconsisten behaviour between datetime library and pandas.to_datetime function when dealing with specific format.
When using slashes, it matches format though it shouldn't

Expected Behavior

It should throw an Exception because the format does not match the values in the Series

Installed Versions

INSTALLED VERSIONS

commit : 87cfe4e
python : 3.10.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.102.1-microsoft-standard-WSL2
Version : #1 SMP Wed Mar 2 00:30:59 UTC 2022
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.0
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 65.3.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.5.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 : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@dadiego91 dadiego91 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 22, 2022
@MarcoGorelli
Copy link
Member

thanks for the report - looks like a duplicate of #12649 ?

@MarcoGorelli MarcoGorelli added Datetime Datetime data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 22, 2022
@dadiego91
Copy link
Author

I think it can be related, but in that ticket they talk about the nuance of matching from the start of the string or the whole, but this is about a completely mismatch of characters, because "-" has nothing to do with "/"

@MarcoGorelli
Copy link
Member

I think it's the same, it's due to the ISO8601 fastpath

(Pdb) p format_is_iso(format)
True

@MarcoGorelli
Copy link
Member

closing for now, but thanks for the report, I'll looking into addressing this as I also find it to be surprising

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

2 participants