1
1
# -*- coding: utf-8 -*-
2
2
3
- from cpython cimport (Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE,
4
- PyUnicode_AsASCIIString)
3
+ from cpython cimport Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE
5
4
6
5
from cpython.datetime cimport (datetime, date,
7
6
PyDateTime_IMPORT,
@@ -13,6 +12,7 @@ from cpython.datetime cimport (datetime, date,
13
12
PyDateTime_IMPORT
14
13
15
14
from numpy cimport int64_t
15
+ from pandas._libs.tslibs.util cimport get_string_data
16
16
17
17
cdef extern from " src/datetime/np_datetime.h" :
18
18
int cmp_npy_datetimestruct(npy_datetimestruct * a,
@@ -174,30 +174,11 @@ cdef inline int64_t pydate_to_dt64(date val, npy_datetimestruct *dts):
174
174
cdef inline int _string_to_dts(object val, npy_datetimestruct* dts,
175
175
int * out_local, int * out_tzoffset) except ? - 1 :
176
176
cdef:
177
- int result
177
+ Py_ssize_t length
178
178
char * tmp
179
179
180
- if isinstance (val, unicode ):
181
- val = PyUnicode_AsASCIIString(val)
182
-
183
- tmp = val
184
- result = _cstring_to_dts(tmp, len (val), dts, out_local, out_tzoffset)
185
-
186
- if result == - 1 :
180
+ if not get_string_data(val, & tmp, & length):
187
181
raise ValueError (' Unable to parse %s ' % str (val))
188
- return result
189
-
190
-
191
- cdef inline int _cstring_to_dts(char * val, int length,
192
- npy_datetimestruct* dts,
193
- int * out_local, int * out_tzoffset) except ? - 1 :
194
- # Note: without this "extra layer" between _string_to_dts
195
- # and parse_iso_8601_datetime, calling _string_to_dts raises
196
- # `SystemError: <class 'str'> returned a result with an error set`
197
- # in Python3
198
- cdef:
199
- int result
182
+ return parse_iso_8601_datetime(tmp, length,
183
+ dts, out_local, out_tzoffset)
200
184
201
- result = parse_iso_8601_datetime(val, length,
202
- dts, out_local, out_tzoffset)
203
- return result
0 commit comments