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

DOC: remove statement that %S parses all the way up to nanosecond even if no decimal place present #49231

Closed
1 task done
MarcoGorelli opened this issue Oct 21, 2022 · 1 comment · Fixed by #49349
Closed
1 task done
Assignees
Labels

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Oct 21, 2022

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.to_datetime.html

Documentation problem

The sentence

"%S" without "%f" will capture all the way up to nanoseconds if present as decimal places, and will also handle the case where the number of seconds is an integer.

isn't generally true - it's only true for the ISO8601 fastpath, and that's because of a bug (which I'm looking at addressing)

Demonstration of the issue:

>>> import pandas as pd
>>> pd.to_datetime('2000-01-01 00:00:00.123456', format='%Y-%m-%d %H:%M:%S')  # iso8601 fastpath
Timestamp('2000-01-01 00:00:00.123456')
>>> pd.to_datetime('2000|01|01 00:00:00.123456', format='%Y|%m|%d %H:%M:%S')  # no fastpath
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/megorelli/.venv/lib/python3.9/site-packages/pandas/core/tools/datetimes.py", line 1102, in to_datetime
    result = convert_listlike(np.array([arg]), format)[0]
  File "/home/megorelli/.venv/lib/python3.9/site-packages/pandas/core/tools/datetimes.py", line 430, in _convert_listlike_datetimes
    res = _to_datetime_with_format(
  File "/home/megorelli/.venv/lib/python3.9/site-packages/pandas/core/tools/datetimes.py", line 538, in _to_datetime_with_format
    res = _array_strptime_with_fallback(
  File "/home/megorelli/.venv/lib/python3.9/site-packages/pandas/core/tools/datetimes.py", line 473, in _array_strptime_with_fallback
    result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors)
  File "pandas/_libs/tslibs/strptime.pyx", line 156, in pandas._libs.tslibs.strptime.array_strptime
ValueError: unconverted data remains: .123456

Suggested fix for documentation

  1. remove this from the format : str, default None section

"%S" without "%f" will capture all the way up to nanoseconds if present as decimal places, and will also handle the case where the number of seconds is an integer.

  1. remove this from the "Differences with strptime behavior" section

"%S" without "%f" will capture all the way up to nanoseconds if present as decimal places.

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

Successfully merging a pull request may close this issue.

2 participants