Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] 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
>>> pd.core.tools.datetimes.guess_datetime_format("2019-07-16 00:00:00.333333333")
'%Y-%m-%d %H:%M:%S.%f'
Issue Description
The number of digits in the sub-second data appears to be missing. Ideally the format I was looking for was %Y-%m-%d %H:%M:%S.%9f'
Expected Behavior
>>> pd.core.tools.datetimes.guess_datetime_format("2019-07-16 00:00:00.333333333")
'%Y-%m-%d %H:%M:%S.%9f'
>>> pd.core.tools.datetimes.guess_datetime_format("2019-07-16 00:00:00.333333")
'%Y-%m-%d %H:%M:%S.%6f'
Installed Versions
Comment From: mroeschke
I don't think guess_datetime_format
ever supported returning the number of digits in subsecond data but I suppose that could be supported
cc @MarcoGorelli
Comment From: MarcoGorelli
I don't think Python allows for %6f
as a format: perhaps you're thinking of Rust?
In [10]: datetime.strptime('2019-07-16 00:00:00.333333', '%Y-%m-%d %H:%M:%S.%6f')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In [10], line 1
----> 1 datetime.strptime('2019-07-16 00:00:00.333333', '%Y-%m-%d %H:%M:%S.%6f')
File /usr/lib/python3.8/_strptime.py:568, in _strptime_datetime(cls, data_string, format)
565 def _strptime_datetime(cls, data_string, format="%a %b %d %H:%M:%S %Y"):
566 """Return a class cls instance based on the input string and the
567 format string."""
--> 568 tt, fraction, gmtoff_fraction = _strptime(data_string, format)
569 tzname, gmtoff = tt[-2:]
570 args = tt[:6] + (fraction,)
File /usr/lib/python3.8/_strptime.py:341, in _strptime(data_string, format)
339 bad_directive = "%"
340 del err
--> 341 raise ValueError("'%s' is a bad directive in format '%s'" %
342 (bad_directive, format)) from None
343 # IndexError only occurs when the format string is "%"
344 except IndexError:
ValueError: '6' is a bad directive in format '%Y-%m-%d %H:%M:%S.%6f'
Comment From: mroeschke
Yeah it appears that C++ can accept digits corresponding to microseconds which this method isn't intended to support, so closing as wont fix