@@ -2123,13 +2123,24 @@ cdef inline convert_to_timedelta64(object ts, object unit, object coerce):
21232123 raise ValueError (" Invalid type for timedelta scalar: %s " % type (ts))
21242124 return ts.astype(' timedelta64[ns]' )
21252125
2126- def array_strptime (ndarray[object] values , object fmt , coerce = False ):
2126+ def array_strptime (ndarray[object] values , object fmt , bint exact = True , bint coerce = False ):
2127+ """
2128+ Parameters
2129+ ----------
2130+ values : ndarray of string-like objects
2131+ fmt : string-like regex
2132+ exact : matches must be exact if True, search if False
2133+ coerce : if invalid values found, coerce to NaT
2134+ """
2135+
21272136 cdef:
21282137 Py_ssize_t i, n = len (values)
21292138 pandas_datetimestruct dts
21302139 ndarray[int64_t] iresult
2131- int year, month, day, minute, hour, second, fraction, weekday, julian
2132- object val
2140+ int year, month, day, minute, hour, second, fraction, weekday, julian, tz
2141+ int week_of_year, week_of_year_start
2142+ object val, group_key, ampm, found
2143+ dict found_key
21332144
21342145 global _TimeRE_cache, _regex_cache
21352146 with _cache_lock:
@@ -2198,19 +2209,32 @@ def array_strptime(ndarray[object] values, object fmt, coerce=False):
21982209 else :
21992210 val = str (val)
22002211
2201- found = format_regex.match(val)
2202- if not found:
2203- if coerce :
2204- iresult[i] = iNaT
2205- continue
2206- raise ValueError (" time data %r does not match format %r " %
2207- (values[i], fmt))
2208- if len (val) != found.end():
2209- if coerce :
2210- iresult[i] = iNaT
2211- continue
2212- raise ValueError (" unconverted data remains: %s " %
2213- values[i][found.end():])
2212+ # exact matching
2213+ if exact:
2214+ found = format_regex.match(val)
2215+ if not found:
2216+ if coerce :
2217+ iresult[i] = iNaT
2218+ continue
2219+ raise ValueError (" time data %r does not match format %r (match)" %
2220+ (values[i], fmt))
2221+ if len (val) != found.end():
2222+ if coerce :
2223+ iresult[i] = iNaT
2224+ continue
2225+ raise ValueError (" unconverted data remains: %s " %
2226+ values[i][found.end():])
2227+
2228+ # search
2229+ else :
2230+ found = format_regex.search(val)
2231+ if not found:
2232+ if coerce :
2233+ iresult[i] = iNaT
2234+ continue
2235+ raise ValueError (" time data %r does not match format %r (search)" %
2236+ (values[i], fmt))
2237+
22142238 year = 1900
22152239 month = day = 1
22162240 hour = minute = second = fraction = 0
@@ -4368,10 +4392,14 @@ _TimeRE_cache = TimeRE()
43684392_CACHE_MAX_SIZE = 5 # Max number of regexes stored in _regex_cache
43694393_regex_cache = {}
43704394
4371- def _calc_julian_from_U_or_W (year , week_of_year , day_of_week , week_starts_Mon ):
4395+ cdef _calc_julian_from_U_or_W(int year, int week_of_year, int day_of_week, int week_starts_Mon):
43724396 """ Calculate the Julian day based on the year, week of the year, and day of
43734397 the week, with week_start_day representing whether the week of the year
43744398 assumes the week starts on Sunday or Monday (6 or 0)."""
4399+
4400+ cdef:
4401+ int first_weekday, week_0_length, days_to_week
4402+
43754403 first_weekday = datetime_date(year, 1 , 1 ).weekday()
43764404 # If we are dealing with the %U directive (week starts on Sunday), it's
43774405 # easier to just shift the view to Sunday being the first day of the
0 commit comments