@@ -137,6 +137,7 @@ def array_strptime(
137
137
exact : matches must be exact if True, search if False
138
138
errors : string specifying error handling, {'raise', 'ignore', 'coerce'}
139
139
"""
140
+
140
141
cdef:
141
142
Py_ssize_t i, n = len (values)
142
143
npy_datetimestruct dts
@@ -277,57 +278,45 @@ def array_strptime(
277
278
else :
278
279
val = str (val)
279
280
280
- if iso_format:
281
- string_to_dts_failed = string_to_dts(
282
- val, & dts, & out_bestunit, & out_local,
283
- & out_tzoffset, False , fmt, exact
284
- )
285
- if not string_to_dts_failed:
286
- # No error reported by string_to_dts, pick back up
287
- # where we left off
288
- value = npy_datetimestruct_to_datetime(NPY_FR_ns, & dts)
289
- if out_local == 1 :
290
- # Store the out_tzoffset in seconds
291
- # since we store the total_seconds of
292
- # dateutil.tz.tzoffset objects
293
- tz = timezone(timedelta(minutes = out_tzoffset))
294
- result_timezone[i] = tz
295
- out_local = 0
296
- out_tzoffset = 0
297
- iresult[i] = value
298
- try :
281
+ if iso_format:
282
+ string_to_dts_failed = string_to_dts(
283
+ val, & dts, & out_bestunit, & out_local,
284
+ & out_tzoffset, False , fmt, exact
285
+ )
286
+ if not string_to_dts_failed:
287
+ # No error reported by string_to_dts, pick back up
288
+ # where we left off
289
+ value = npy_datetimestruct_to_datetime(NPY_FR_ns, & dts)
290
+ if out_local == 1 :
291
+ # Store the out_tzoffset in seconds
292
+ # since we store the total_seconds of
293
+ # dateutil.tz.tzoffset objects
294
+ tz = timezone(timedelta(minutes = out_tzoffset))
295
+ result_timezone[i] = tz
296
+ out_local = 0
297
+ out_tzoffset = 0
298
+ iresult[i] = value
299
299
check_dts_bounds(& dts)
300
- except ValueError :
301
- if is_coerce:
302
- iresult[i] = NPY_NAT
303
- continue
304
- raise
305
- continue
300
+ continue
306
301
307
- if parse_today_now(val, & iresult[i], utc):
308
- continue
302
+ if parse_today_now(val, & iresult[i], utc):
303
+ continue
309
304
310
- # Some ISO formats can't be parsed by string_to_dts
311
- # For example, 6-digit YYYYMD. So, if there's an error,
312
- # try the string-matching code below.
305
+ # Some ISO formats can't be parsed by string_to_dts
306
+ # For example, 6-digit YYYYMD. So, if there's an error,
307
+ # try the string-matching code below.
313
308
314
- # exact matching
315
- if exact:
316
- found = format_regex.match(val)
317
- if not found:
318
- if is_coerce:
319
- iresult[i] = NPY_NAT
320
- continue
321
- raise ValueError (f" time data \" {val}\" at position {i} doesn't "
322
- f" match format \" {fmt}\" " )
323
- if len (val) != found.end():
324
- if is_coerce:
325
- iresult[i] = NPY_NAT
326
- continue
327
- raise ValueError (
328
- f" unconverted data remains at position {i}: "
329
- f' "{val[found.end():]}"'
330
- )
309
+ # exact matching
310
+ if exact:
311
+ found = format_regex.match(val)
312
+ if not found:
313
+ raise ValueError (f" time data \" {val}\" at position {i} doesn't "
314
+ f" match format \" {fmt}\" " )
315
+ if len (val) != found.end():
316
+ raise ValueError (
317
+ f" unconverted data remains at position {i}: "
318
+ f' "{val[found.end():]}"'
319
+ )
331
320
332
321
# search
333
322
else :
0 commit comments