Skip to content

Commit d24e728

Browse files
anmyachevvnlitvinov
authored andcommitted
fix problem with const char* value, that return PyUnicode_AsUTF8AndSize in Python3.7 case; added docstring to get_string_data func
1 parent 3551121 commit d24e728

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

pandas/_libs/tslibs/np_datetime.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cdef extern from "src/datetime/np_datetime.h":
3333
npy_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS
3434

3535
cdef extern from "src/datetime/np_datetime_strings.h":
36-
int parse_iso_8601_datetime(char *str, int len,
36+
int parse_iso_8601_datetime(const char *str, int len,
3737
npy_datetimestruct *out,
3838
int *out_local, int *out_tzoffset)
3939

@@ -175,7 +175,7 @@ cdef inline int _string_to_dts(object val, npy_datetimestruct* dts,
175175
int* out_local, int* out_tzoffset) except? -1:
176176
cdef:
177177
Py_ssize_t length
178-
char *tmp
178+
const char* tmp
179179

180180
if not get_string_data(val, &tmp, &length):
181181
raise ValueError('Unable to parse %s' % str(val))

pandas/_libs/tslibs/src/datetime/np_datetime_strings.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ This file implements string parsing and creation for NumPy datetime.
6666
*
6767
* Returns 0 on success, -1 on failure.
6868
*/
69-
int parse_iso_8601_datetime(char *str, int len,
69+
int parse_iso_8601_datetime(const char *str, int len,
7070
npy_datetimestruct *out,
7171
int *out_local, int *out_tzoffset) {
7272
int year_leap = 0;
7373
int i, numdigits;
74-
char *substr, sublen;
74+
const char *substr;
75+
char sublen;
7576

7677
/* If year-month-day are separated by a valid separator,
7778
* months/days without leading zeroes will be parsed

pandas/_libs/tslibs/src/datetime/np_datetime_strings.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ This file implements string parsing and creation for NumPy datetime.
5454
* Returns 0 on success, -1 on failure.
5555
*/
5656
int
57-
parse_iso_8601_datetime(char *str, int len,
57+
parse_iso_8601_datetime(const char *str, int len,
5858
npy_datetimestruct *out,
5959
int *out_local,
6060
int *out_tzoffset);

pandas/_libs/tslibs/util.pxd

+19-2
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,27 @@ cdef inline bint is_nan(object val):
232232
return (is_float_object(val) or is_complex_object(val)) and val != val
233233

234234

235-
cdef inline bint get_string_data(object s, char **buf, Py_ssize_t *length):
235+
cdef inline bint get_string_data(object s, const char **buf,
236+
Py_ssize_t *length):
237+
"""
238+
Extract internal char * buffer of unicode or bytes object `s` to `buf` with
239+
getting length of this internal buffer, that save in `length`.
240+
Return `False` if it failed to extract such buffer for whatever reason
241+
otherwise return `True`
242+
243+
Parameters
244+
----------
245+
s : object
246+
buf : const char**
247+
length : Py_ssize_t*
248+
249+
Returns
250+
-------
251+
bint
252+
"""
236253
if PyUnicode_Check(s):
237254
buf[0] = PyUnicode_AsUTF8AndSize(s, length)
238255
return buf[0] != NULL
239256
if PyBytes_Check(s):
240-
return PyBytes_AsStringAndSize(s, buf, length) == 0
257+
return PyBytes_AsStringAndSize(s, <char**>buf, length) == 0
241258
return False

0 commit comments

Comments
 (0)