@@ -2123,13 +2123,24 @@ cdef inline convert_to_timedelta64(object ts, object unit, object coerce):
2123
2123
raise ValueError (" Invalid type for timedelta scalar: %s " % type (ts))
2124
2124
return ts.astype(' timedelta64[ns]' )
2125
2125
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
+
2127
2136
cdef:
2128
2137
Py_ssize_t i, n = len (values)
2129
2138
pandas_datetimestruct dts
2130
2139
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
2133
2144
2134
2145
global _TimeRE_cache, _regex_cache
2135
2146
with _cache_lock:
@@ -2198,19 +2209,32 @@ def array_strptime(ndarray[object] values, object fmt, coerce=False):
2198
2209
else :
2199
2210
val = str (val)
2200
2211
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
+
2214
2238
year = 1900
2215
2239
month = day = 1
2216
2240
hour = minute = second = fraction = 0
@@ -4368,10 +4392,14 @@ _TimeRE_cache = TimeRE()
4368
4392
_CACHE_MAX_SIZE = 5 # Max number of regexes stored in _regex_cache
4369
4393
_regex_cache = {}
4370
4394
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):
4372
4396
""" Calculate the Julian day based on the year, week of the year, and day of
4373
4397
the week, with week_start_day representing whether the week of the year
4374
4398
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
+
4375
4403
first_weekday = datetime_date(year, 1 , 1 ).weekday()
4376
4404
# If we are dealing with the %U directive (week starts on Sunday), it's
4377
4405
# easier to just shift the view to Sunday being the first day of the
0 commit comments