Skip to content

Commit a52e59c

Browse files
Performance fix
1 parent 27da130 commit a52e59c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pandas/_libs/hashtable_class_helper.pxi.in

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
1212
from pandas._libs.tslibs.util cimport get_c_string
1313
from pandas._libs.missing cimport C_NA
1414

15+
cdef extern from "Python.h":
16+
# Note: importing extern-style allows us to declare these as nogil
17+
# functions, whereas `from cpython cimport` does not.
18+
void PyErr_Clear() nogil
19+
1520
{{py:
1621

1722
# name, dtype, c_type
@@ -789,8 +794,10 @@ cdef class StringHashTable(HashTable):
789794
labels[i] = na_sentinel
790795
else:
791796
# if ignore_na is False, we also stringify NaN/None/etc.
792-
v = get_c_string(<str>val) if val.isprintable() else \
793-
get_c_string(<str>repr(val))
797+
v = get_c_string(<str>val)
798+
if v == NULL:
799+
PyErr_Clear()
800+
v = get_c_string(<str>repr(val))
794801
vecs[i] = v
795802

796803
# compute

0 commit comments

Comments
 (0)