@@ -117,14 +117,16 @@ def _test_format_is_iso(f: str) -> bool:
117
117
118
118
119
119
cdef bint parse_today_now(
120
- str val , int64_t* iresult , bint utc , NPY_DATETIMEUNIT creso
120
+ str val , int64_t* iresult , bint utc , NPY_DATETIMEUNIT creso , bint infer_reso = False
121
121
):
122
122
# We delay this check for as long as possible
123
123
# because it catches relatively rare cases
124
124
cdef:
125
125
_Timestamp ts
126
126
127
127
if val == " now" :
128
+ if infer_reso:
129
+ creso = NPY_DATETIMEUNIT.NPY_FR_us
128
130
if utc:
129
131
ts = < _Timestamp> Timestamp.utcnow()
130
132
iresult[0 ] = ts._as_creso(creso)._value
@@ -135,6 +137,8 @@ cdef bint parse_today_now(
135
137
iresult[0 ] = ts._as_creso(creso)._value
136
138
return True
137
139
elif val == " today" :
140
+ if infer_reso:
141
+ creso = NPY_DATETIMEUNIT.NPY_FR_us
138
142
ts = < _Timestamp> Timestamp.today()
139
143
iresult[0 ] = ts._as_creso(creso)._value
140
144
return True
@@ -348,27 +352,33 @@ def array_strptime(
348
352
else :
349
353
item_reso = NPY_DATETIMEUNIT.NPY_FR_us
350
354
state.update_creso(item_reso)
355
+ if infer_reso:
356
+ creso = state.creso
351
357
tz_out = state.process_datetime(val, tz_out, utc)
352
358
if isinstance (val, _Timestamp):
353
- val = (< _Timestamp> val)._as_creso(state. creso)
359
+ val = (< _Timestamp> val)._as_creso(creso)
354
360
iresult[i] = val.tz_localize(None )._value
355
361
else :
356
362
iresult[i] = pydatetime_to_dt64(
357
- val.replace(tzinfo = None ), & dts, reso = state. creso
363
+ val.replace(tzinfo = None ), & dts, reso = creso
358
364
)
359
- check_dts_bounds(& dts, state. creso)
365
+ check_dts_bounds(& dts, creso)
360
366
result_timezone[i] = val.tzinfo
361
367
continue
362
368
elif PyDate_Check(val):
363
369
item_reso = NPY_DATETIMEUNIT.NPY_FR_s
364
370
state.update_creso(item_reso)
365
- iresult[i] = pydate_to_dt64(val, & dts, reso = state.creso)
366
- check_dts_bounds(& dts, state.creso)
371
+ if infer_reso:
372
+ creso = state.creso
373
+ iresult[i] = pydate_to_dt64(val, & dts, reso = creso)
374
+ check_dts_bounds(& dts, creso)
367
375
continue
368
376
elif is_datetime64_object(val):
369
377
item_reso = get_supported_reso(get_datetime64_unit(val))
370
378
state.update_creso(item_reso)
371
- iresult[i] = get_datetime64_nanos(val, state.creso)
379
+ if infer_reso:
380
+ creso = state.creso
381
+ iresult[i] = get_datetime64_nanos(val, creso)
372
382
continue
373
383
elif (
374
384
(is_integer_object(val) or is_float_object(val))
@@ -394,7 +404,9 @@ def array_strptime(
394
404
# where we left off
395
405
item_reso = get_supported_reso(out_bestunit)
396
406
state.update_creso(item_reso)
397
- value = npy_datetimestruct_to_datetime(state.creso, & dts)
407
+ if infer_reso:
408
+ creso = state.creso
409
+ value = npy_datetimestruct_to_datetime(creso, & dts)
398
410
if out_local == 1 :
399
411
# Store the out_tzoffset in seconds
400
412
# since we store the total_seconds of
@@ -404,12 +416,14 @@ def array_strptime(
404
416
out_local = 0
405
417
out_tzoffset = 0
406
418
iresult[i] = value
407
- check_dts_bounds(& dts)
419
+ check_dts_bounds(& dts, creso )
408
420
continue
409
421
410
- if parse_today_now(val, & iresult[i], utc, state. creso):
422
+ if parse_today_now(val, & iresult[i], utc, creso, infer_reso = infer_reso ):
411
423
item_reso = NPY_DATETIMEUNIT.NPY_FR_us
412
424
state.update_creso(item_reso)
425
+ if infer_reso:
426
+ creso = state.creso
413
427
continue
414
428
415
429
# Some ISO formats can't be parsed by string_to_dts
@@ -424,8 +438,10 @@ def array_strptime(
424
438
val, fmt, exact, format_regex, locale_time, & dts, & item_reso
425
439
)
426
440
state.update_creso(item_reso)
427
- iresult[i] = npy_datetimestruct_to_datetime(state.creso, & dts)
428
- check_dts_bounds(& dts)
441
+ if infer_reso:
442
+ creso = state.creso
443
+ iresult[i] = npy_datetimestruct_to_datetime(creso, & dts)
444
+ check_dts_bounds(& dts, creso)
429
445
result_timezone[i] = tz
430
446
431
447
except (ValueError , OutOfBoundsDatetime) as ex:
0 commit comments