@@ -264,14 +264,26 @@ cdef bint _does_string_look_like_time(str parse_string):
264
264
return 0 <= hour <= 23 and 0 <= minute <= 59
265
265
266
266
267
- def parse_datetime_string (
267
+ def py_parse_datetime_string (
268
+ str date_string , bint dayfirst = False , bint yearfirst = False
269
+ ):
270
+ # Python-accessible version for testing (we can't just make
271
+ # parse_datetime_string cpdef bc it has a pointer argument)
272
+ cdef:
273
+ NPY_DATETIMEUNIT out_bestunit
274
+
275
+ return parse_datetime_string(date_string, dayfirst, yearfirst, & out_bestunit)
276
+
277
+
278
+ cdef datetime parse_datetime_string(
268
279
# NB: This will break with np.str_ (GH#32264) even though
269
280
# isinstance(npstrobj, str) evaluates to True, so caller must ensure
270
281
# the argument is *exactly* 'str'
271
282
str date_string,
272
- bint dayfirst = False ,
273
- bint yearfirst = False ,
274
- ) -> datetime:
283
+ bint dayfirst,
284
+ bint yearfirst,
285
+ NPY_DATETIMEUNIT* out_bestunit
286
+ ):
275
287
"""
276
288
Parse datetime string, only returns datetime.
277
289
Also cares special handling matching time patterns.
@@ -287,7 +299,6 @@ def parse_datetime_string(
287
299
288
300
cdef:
289
301
datetime dt
290
- NPY_DATETIMEUNIT out_bestunit
291
302
bint is_quarter = 0
292
303
293
304
if not _does_string_look_like_datetime(date_string):
@@ -299,13 +310,13 @@ def parse_datetime_string(
299
310
yearfirst = yearfirst)
300
311
return dt
301
312
302
- dt = _parse_delimited_date(date_string, dayfirst, & out_bestunit)
313
+ dt = _parse_delimited_date(date_string, dayfirst, out_bestunit)
303
314
if dt is not None :
304
315
return dt
305
316
306
317
try :
307
318
dt = _parse_dateabbr_string(
308
- date_string, _DEFAULT_DATETIME, None , & out_bestunit, & is_quarter
319
+ date_string, _DEFAULT_DATETIME, None , out_bestunit, & is_quarter
309
320
)
310
321
return dt
311
322
except DateParseError:
@@ -315,7 +326,7 @@ def parse_datetime_string(
315
326
316
327
dt = dateutil_parse(date_string, default = _DEFAULT_DATETIME,
317
328
dayfirst = dayfirst, yearfirst = yearfirst,
318
- ignoretz = False , out_bestunit = & out_bestunit)
329
+ ignoretz = False , out_bestunit = out_bestunit)
319
330
return dt
320
331
321
332
0 commit comments