question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: not able to convert non-zero padded hour to timestamp.

See original GitHub issue

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.to_datetime('2018-08-18 9', format='%Y-%m-%d %H', infer_datetime_format=True)

Issue Description

Not able to convert the non-zero padded Hour and zero padded date to timestamp. ParserError: Unknown string format: 2018-08-18 9

Not having any issue converting: pd.to_datetime('2018-08-18 09', format='%Y-%m-%d %H', infer_datetime_format=True) OUTPUT: Timestamp('2018-08-18 09:00:00')

Expected Behavior

I am expecting Timestamp('2018-08-18 09:00:00') with non-zero padded hour.

Installed Versions

INSTALLED VERSIONS

commit : 4bfe3d07b4858144c219b9346329027024102ab6 python : 3.8.13.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19043 machine : AMD64 processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_India.1252

pandas : 1.4.2 numpy : 1.20.3 pytz : 2021.3 dateutil : 2.8.2 pip : 21.2.2 setuptools : 58.0.4 Cython : 0.29.25 pytest : 6.2.5 hypothesis : None sphinx : 4.4.0 blosc : None feather : None xlsxwriter : 3.0.2 lxml.etree : 4.7.1 html5lib : 1.1 pymysql : None psycopg2 : 2.9.1 jinja2 : 2.11.3 IPython : 8.2.0 pandas_datareader: None bs4 : 4.10.0 bottleneck : 1.3.4 brotli : fastparquet : None fsspec : 2022.02.0 gcsfs : None markupsafe : 2.0.1 matplotlib : 3.5.0 numba : 0.54.1 numexpr : 2.8.1 odfpy : None openpyxl : 3.0.9 pandas_gbq : None pyarrow : 7.0.0 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.7.3 snappy : None sqlalchemy : 1.4.27 tables : 3.6.1 tabulate : None xarray : None xlrd : 2.0.1 xlwt : 1.3.0 zstandard : None

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoGorellicommented, Dec 17, 2022

This is the part of the code that’d need changing if you wanted to support this

https://github.com/pandas-dev/pandas/blob/a37b78d534cd25e21d2ab64318ceae808df46c89/pandas/_libs/tslibs/src/datetime/np_datetime_strings.c#L581-L601

In the meantime, I think it’s fine to error

0reactions
MarcoGorellicommented, Dec 17, 2022

also, looks like a dupe of https://github.com/pandas-dev/pandas/issues/21422, so let’s close in favour of that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing non-zero padded timestamps in Python - Stack Overflow
My solution for this edge case was to catch the exception, try parsing it with a %H , with a quick check that...
Read more >
change non-zero padded hour and minute into 24hr time
It is currently in a format that stores midnight values as 2400 and that should be changed to 0000. The format also does...
Read more >
The EPIC Time Conversion and Manipulation Thread!
Convert a Scrape Sensor date string to timestamp. Garden Irrigation ... 23 %I Hour (12-hour clock) as a zero-padded decimal number.
Read more >
8.2: Data Type Formatting Functions - PostgreSQL
The PostgreSQL formatting functions provide a powerful set of tools for converting various data types (date/time, integer, floating point, ...
Read more >
Custom date and time format strings | Microsoft Learn
Any string that is not a standard date and time format string is interpreted as a ... Unable to convert '12-30-2011' to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found