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

ENH: Add support for more placeholders in guess_datetime_format #43900

Merged
merged 1 commit into from
Oct 17, 2021

Conversation

davesque
Copy link
Contributor

@davesque davesque commented Oct 6, 2021

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.

I'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".

@davesque davesque force-pushed the fix-guess-datetime-format branch from dcfa5d8 to aa0a990 Compare October 6, 2021 06:45
@davesque davesque force-pushed the fix-guess-datetime-format branch 2 times, most recently from a029a72 to 2541b3d Compare October 6, 2021 15:52
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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`)
Copy link
Contributor

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

Copy link
Member

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)

@jreback jreback added the Datetime Datetime data dtype label Oct 6, 2021
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:
Copy link
Member

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?

Copy link
Contributor Author

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.
@davesque davesque force-pushed the fix-guess-datetime-format branch from eb30608 to 91d172f Compare October 7, 2021 04:49
@davesque davesque requested review from mroeschke and jreback October 7, 2021 04:51
@davesque
Copy link
Contributor Author

davesque commented Oct 7, 2021

@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.

Copy link
Member

@mroeschke mroeschke left a 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

@davesque
Copy link
Contributor Author

davesque commented Oct 8, 2021

@jreback Anything else needed for this? Not sure what happened with the cancelled github action.

@mroeschke mroeschke added this to the 1.4 milestone Oct 13, 2021
@mroeschke
Copy link
Member

@davesque sorry for the delay. Could you merge in master one more time, and then this should be good to merge.

Copy link
Contributor

@jreback jreback left a 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;'

@mroeschke mroeschke merged commit 4f36b02 into pandas-dev:master Oct 17, 2021
@mroeschke
Copy link
Member

Thanks @davesque

(May be a performance improvement for all formats according to #43900 (comment))

@davesque davesque deleted the fix-guess-datetime-format branch October 25, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add support for more placeholders in guess_datetime_format
3 participants