Skip to content

Commit 359f7dd

Browse files
author
Shashwat
committed
performace: used regular expression 50465
1 parent 0641183 commit 359f7dd

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

pandas/_libs/tslibs/parsing.pyx

+4-10
Original file line numberDiff line numberDiff line change
@@ -824,17 +824,11 @@ def format_is_iso(f: str) -> bint:
824824
Generally of form YYYY-MM-DDTHH:MM:SS - date separator can be different
825825
but must be consistent. Leading 0s in dates and times are optional.
826826
"""
827-
iso_template = "%Y{date_sep}%m{date_sep}%d{time_sep}%H:%M:%S{micro_or_tz}".format
827+
iso_regex = \
828+
r"^\d{4}(-\d{2}(-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(([+-]\d{2}:\d{2})|Z)?)?)?)?$"
828829
excluded_formats = ["%Y%m%d", "%Y%m", "%Y"]
829-
830-
for date_sep in [" ", "/", "\\", "-", ".", ""]:
831-
for time_sep in [" ", "T"]:
832-
for micro_or_tz in ["", "%z", ".%f", ".%f%z"]:
833-
if (iso_template(date_sep=date_sep,
834-
time_sep=time_sep,
835-
micro_or_tz=micro_or_tz,
836-
).startswith(f) and f not in excluded_formats):
837-
return True
830+
if re.match(iso_regex, f) and f not in excluded_formats:
831+
return True
838832
return False
839833

840834

0 commit comments

Comments
 (0)