Skip to content

PERF use regular expression in format_is_iso? #50465

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

Closed
MarcoGorelli opened this issue Dec 28, 2022 · 1 comment · Fixed by #50468
Closed

PERF use regular expression in format_is_iso? #50465

MarcoGorelli opened this issue Dec 28, 2022 · 1 comment · Fixed by #50468
Assignees
Labels
Datetime Datetime data dtype good first issue Performance Memory or execution speed performance

Comments

@MarcoGorelli
Copy link
Member

Suggested here: #50242 (comment)

Here are the relevant lines of code:

def format_is_iso(f: str) -> bint:
"""
Does format match the iso8601 set that can be handled by the C parser?
Generally of form YYYY-MM-DDTHH:MM:SS - date separator can be different
but must be consistent. Leading 0s in dates and times are optional.
"""
iso_template = "%Y{date_sep}%m{date_sep}%d{time_sep}%H:%M:%S{micro_or_tz}".format
excluded_formats = ["%Y%m%d", "%Y%m", "%Y"]
for date_sep in [" ", "/", "\\", "-", ".", ""]:
for time_sep in [" ", "T"]:
for micro_or_tz in ["", "%z", ".%f", ".%f%z"]:
if (iso_template(date_sep=date_sep,
time_sep=time_sep,
micro_or_tz=micro_or_tz,
).startswith(f) and f not in excluded_formats):
return True
return False

@MarcoGorelli MarcoGorelli added Datetime Datetime data dtype Performance Memory or execution speed performance good first issue labels Dec 28, 2022
@ShashwatAgrawal20
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype good first issue Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants