Skip to content

Commit 685cf7f

Browse files
authored
CLN remove unneccessary code from array_strptime which doesn't spark joy (#50830)
simplify Co-authored-by: MarcoGorelli <>
1 parent e462776 commit 685cf7f

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

pandas/_libs/tslibs/strptime.pyx

+40-41
Original file line numberDiff line numberDiff line change
@@ -183,52 +183,51 @@ def array_strptime(
183183
bint found_naive = False
184184
bint found_tz = False
185185
tzinfo tz_out = None
186-
bint iso_format = fmt is not None and format_is_iso(fmt)
186+
bint iso_format = format_is_iso(fmt)
187187
NPY_DATETIMEUNIT out_bestunit
188188
int out_local = 0, out_tzoffset = 0
189189

190190
assert is_raise or is_ignore or is_coerce
191191

192-
if fmt is not None:
193-
if "%W" in fmt or "%U" in fmt:
194-
if "%Y" not in fmt and "%y" not in fmt:
195-
raise ValueError("Cannot use '%W' or '%U' without day and year")
196-
if "%A" not in fmt and "%a" not in fmt and "%w" not in fmt:
197-
raise ValueError("Cannot use '%W' or '%U' without day and year")
198-
elif "%Z" in fmt and "%z" in fmt:
199-
raise ValueError("Cannot parse both %Z and %z")
200-
elif "%j" in fmt and "%G" in fmt:
201-
raise ValueError("Day of the year directive '%j' is not "
202-
"compatible with ISO year directive '%G'. "
203-
"Use '%Y' instead.")
204-
elif "%G" in fmt and (
205-
"%V" not in fmt
206-
or not (
207-
"%A" in fmt
208-
or "%a" in fmt
209-
or "%w" in fmt
210-
or "%u" in fmt
211-
)
212-
):
213-
raise ValueError("ISO year directive '%G' must be used with "
214-
"the ISO week directive '%V' and a weekday "
215-
"directive '%A', '%a', '%w', or '%u'.")
216-
elif "%V" in fmt and "%Y" in fmt:
217-
raise ValueError("ISO week directive '%V' is incompatible with "
218-
"the year directive '%Y'. Use the ISO year "
219-
"'%G' instead.")
220-
elif "%V" in fmt and (
221-
"%G" not in fmt
222-
or not (
223-
"%A" in fmt
224-
or "%a" in fmt
225-
or "%w" in fmt
226-
or "%u" in fmt
227-
)
228-
):
229-
raise ValueError("ISO week directive '%V' must be used with "
230-
"the ISO year directive '%G' and a weekday "
231-
"directive '%A', '%a', '%w', or '%u'.")
192+
if "%W" in fmt or "%U" in fmt:
193+
if "%Y" not in fmt and "%y" not in fmt:
194+
raise ValueError("Cannot use '%W' or '%U' without day and year")
195+
if "%A" not in fmt and "%a" not in fmt and "%w" not in fmt:
196+
raise ValueError("Cannot use '%W' or '%U' without day and year")
197+
elif "%Z" in fmt and "%z" in fmt:
198+
raise ValueError("Cannot parse both %Z and %z")
199+
elif "%j" in fmt and "%G" in fmt:
200+
raise ValueError("Day of the year directive '%j' is not "
201+
"compatible with ISO year directive '%G'. "
202+
"Use '%Y' instead.")
203+
elif "%G" in fmt and (
204+
"%V" not in fmt
205+
or not (
206+
"%A" in fmt
207+
or "%a" in fmt
208+
or "%w" in fmt
209+
or "%u" in fmt
210+
)
211+
):
212+
raise ValueError("ISO year directive '%G' must be used with "
213+
"the ISO week directive '%V' and a weekday "
214+
"directive '%A', '%a', '%w', or '%u'.")
215+
elif "%V" in fmt and "%Y" in fmt:
216+
raise ValueError("ISO week directive '%V' is incompatible with "
217+
"the year directive '%Y'. Use the ISO year "
218+
"'%G' instead.")
219+
elif "%V" in fmt and (
220+
"%G" not in fmt
221+
or not (
222+
"%A" in fmt
223+
or "%a" in fmt
224+
or "%w" in fmt
225+
or "%u" in fmt
226+
)
227+
):
228+
raise ValueError("ISO week directive '%V' must be used with "
229+
"the ISO year directive '%G' and a weekday "
230+
"directive '%A', '%a', '%w', or '%u'.")
232231

233232
global _TimeRE_cache, _regex_cache
234233
with _cache_lock:

0 commit comments

Comments
 (0)