Skip to content

Commit 33dc0b3

Browse files
Pushed the fix a bit higher up in the call chain to prevent unneeded impact
1 parent bb77b0b commit 33dc0b3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pandas/_libs/hashtable_class_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ cdef class StringHashTable(HashTable):
789789
labels[i] = na_sentinel
790790
else:
791791
# if ignore_na is False, we also stringify NaN/None/etc.
792-
v = get_c_string(<str>val)
792+
v = get_c_string(<str>val) if val.isprintable() else get_c_string(<str>repr(val))
793793
vecs[i] = v
794794

795795
# compute

pandas/_libs/tslibs/util.pxd

+6-4
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ cdef inline const char* get_c_string_buf_and_size(str py_string,
236236
237237
Returns
238238
-------
239-
c_string_buf : const char*
239+
buf : const char*
240240
"""
241-
if not py_string.isprintable():
242-
return PyUnicode_AsUTF8AndSize(repr(py_string), length)
243-
return PyUnicode_AsUTF8AndSize(py_string, length)
241+
cdef:
242+
const char *buf
243+
244+
buf = PyUnicode_AsUTF8AndSize(py_string, length)
245+
return buf
244246

245247

246248
cdef inline const char* get_c_string(str py_string):

0 commit comments

Comments
 (0)