-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: Add support for more placeholders in guess_datetime_format
#43900
ENH: Add support for more placeholders in guess_datetime_format
#43900
Conversation
dcfa5d8
to
aa0a990
Compare
a029a72
to
2541b3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @mroeschke
doc/source/whatsnew/v1.4.0.rst
Outdated
@@ -129,6 +129,7 @@ Other enhancements | |||
- :meth:`DataFrame.__pos__`, :meth:`DataFrame.__neg__` now retain ``ExtensionDtype`` dtypes (:issue:`43883`) | |||
- The error raised when an optional dependency can't be imported now includes the original exception, for easier investigation (:issue:`43882`) | |||
- Added :meth:`.ExponentialMovingWindow.sum` (:issue:`13297`) | |||
- :func:`guess_datetime_format` now correctly guesses the format of datetime strings with day of week and AM/PM placeholders (:issue:`43901`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not public, day :func:`to_datetime`
and indicate what this does (speed it up?). this should go under datetime section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is probably applicable to the infer_datetime_format
kwarg in to_datetime
(worth a mention if it improves performance with that option)
pandas/_libs/tslibs/parsing.pyx
Outdated
break | ||
parsed_formatted = parsed_datetime.strftime(attr_format) | ||
# The result of `.strftime("%Z")` on a dt with no timezone is "" | ||
if len(parsed_formatted) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it just sufficient to check attr_format in ("%Z", "%z")
since the other codes will always parse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, probably a better approach.
…ndas-dev#43901) Add support for day of week and meridiem placeholders and any combination of placeholders supported by `strftime` that do not correspond to a datetime attribute.
eb30608
to
91d172f
Compare
@jreback @mroeschke Made the requested changes. Went ahead and squashed everything to have just one commit. Though I'm not sure if reviewers typically prefer to have the commit history of the PR until final approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One whatsnew comment otherwise LGTM
@jreback Anything else needed for this? Not sure what happened with the cancelled github action. |
@davesque sorry for the delay. Could you merge in master one more time, and then this should be good to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could narrow the whatsnew note to say only for '%p;'
Thanks @davesque (May be a performance improvement for all formats according to #43900 (comment)) |
Add support for day of week and meridiem placeholders and any
combination of placeholders supported by
strftime
that do notcorrespond to a datetime attribute.
guess_datetime_format
#43901I'm not sure if this fix actually qualifies as a bug fix and not and enhancement. Before,
guess_datetime_format
would output a somewhat invalid format string that included literal content from the parsed datetime such as "Tue" or "AM".