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

Format mismatch doesn't coerce to NaT #24763

Closed
shuttle1987 opened this issue Jan 14, 2019 · 1 comment · Fixed by #24815
Closed

Format mismatch doesn't coerce to NaT #24763

shuttle1987 opened this issue Jan 14, 2019 · 1 comment · Fixed by #24815
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@shuttle1987
Copy link

Code Sample, a copy-pastable example if possible

>>> pd.to_datetime("00:01:18", format='H%:M%:S%', errors='coerce', infer_datetime_format=False)
"00:01:18"

Problem description

In this example code I have made a mistake with the format 'H%:M%:S%' it should be '%H:%M:%S'
instead. Since I have specified errors to 'coerce' getting a string as the return value here seems very surprising to me.

Expected Output

Given that I have specified errors='coerce' and infer_datetime_format=False I'd expect to get a NaT result here.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.7.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-1031-aws
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 3.8.0
pip: 18.1
setuptools: 40.2.0
Cython: 0.28.5
numpy: 1.15.1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: 1.7.9
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 2.2.3
openpyxl: 2.5.6
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.0
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@TomAugspurger TomAugspurger added the Datetime Datetime data dtype label Jan 14, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Jan 14, 2019
@WillAyd WillAyd added the Bug label Jan 14, 2019
@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Jan 17, 2019
@MarcoGorelli
Copy link
Member

I think this should just raise - errors controls invalid parsing, whereas here the error happens before the parsing even begins

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

Successfully merging a pull request may close this issue.

5 participants