Skip to content

Commit c90635b

Browse files
anmyachevvnlitvinov
authored andcommitted
replaced get_c_string to get_string_data, added 'note' paragraph in get_string_data docstring
1 parent 44efe95 commit c90635b

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

pandas/_libs/hashtable_class_helper.pxi.in

+10-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
99
# VectorData
1010
# ----------------------------------------------------------------------
1111

12+
from pandas._libs.tslibs.util cimport get_string_data
13+
1214
{{py:
1315

1416
# name, dtype, arg
@@ -595,7 +597,7 @@ cdef class StringHashTable(HashTable):
595597
cdef:
596598
khiter_t k
597599
const char *v
598-
v = util.get_c_string(val)
600+
get_string_data(val, &v, NULL)
599601

600602
k = kh_get_str(self.table, v)
601603
if k != self.table.n_buckets:
@@ -609,7 +611,7 @@ cdef class StringHashTable(HashTable):
609611
int ret = 0
610612
const char *v
611613

612-
v = util.get_c_string(val)
614+
get_string_data(val, &v, NULL)
613615

614616
k = kh_put_str(self.table, v, &ret)
615617
self.table.keys[k] = key
@@ -632,7 +634,7 @@ cdef class StringHashTable(HashTable):
632634
vecs = <const char **>malloc(n * sizeof(char *))
633635
for i in range(n):
634636
val = values[i]
635-
v = util.get_c_string(val)
637+
get_string_data(val, &v, NULL)
636638
vecs[i] = v
637639

638640
with nogil:
@@ -662,9 +664,9 @@ cdef class StringHashTable(HashTable):
662664
val = values[i]
663665

664666
if isinstance(val, (str, unicode)):
665-
v = util.get_c_string(val)
667+
get_string_data(val, &v, NULL)
666668
else:
667-
v = util.get_c_string(self.na_string_sentinel)
669+
get_string_data(self.na_string_sentinel, &v, NULL)
668670
vecs[i] = v
669671

670672
with nogil:
@@ -695,9 +697,9 @@ cdef class StringHashTable(HashTable):
695697
val = values[i]
696698

697699
if isinstance(val, (str, unicode)):
698-
v = util.get_c_string(val)
700+
get_string_data(val, &v, NULL)
699701
else:
700-
v = util.get_c_string(self.na_string_sentinel)
702+
get_string_data(self.na_string_sentinel, &v, NULL)
701703
vecs[i] = v
702704

703705
with nogil:
@@ -776,7 +778,7 @@ cdef class StringHashTable(HashTable):
776778
labels[i] = na_sentinel
777779
else:
778780
# if ignore_na is False, we also stringify NaN/None/etc.
779-
v = util.get_c_string(val)
781+
get_string_data(val, &v, NULL)
780782
vecs[i] = v
781783

782784
# compute

pandas/_libs/tslibs/util.pxd

+5
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ cdef inline bint get_string_data(object s, const char **buf,
241241
Return `False` if it failed to extract such buffer for whatever reason
242242
otherwise return `True`
243243
244+
Note
245+
----
246+
python object owns memory, `buf` should not be freed
247+
`length` can be NULL
248+
244249
Parameters
245250
----------
246251
s : object

pandas/_libs/util.pxd

-15
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@ cdef extern from "numpy/arrayobject.h":
1515
NPY_ARRAY_F_CONTIGUOUS
1616

1717

18-
cdef extern from *:
19-
"""
20-
// returns ASCII or UTF8 (py3) view on python str
21-
// python object owns memory, should not be freed
22-
static const char* get_c_string(PyObject* obj) {
23-
#if PY_VERSION_HEX >= 0x03000000
24-
return PyUnicode_AsUTF8(obj);
25-
#else
26-
return PyString_AsString(obj);
27-
#endif
28-
}
29-
"""
30-
const char *get_c_string(object) except NULL
31-
32-
3318
cdef extern from "src/headers/stdint.h":
3419
enum: UINT8_MAX
3520
enum: UINT16_MAX

0 commit comments

Comments
 (0)