Skip to content

Commit 7fd9d1f

Browse files
Use try/except block to properly catch and handle the exception
Now no more warnings
1 parent e878fdc commit 7fd9d1f

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

pandas/_libs/hashtable_class_helper.pxi.in

-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ 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-
void PyErr_Clear()
17-
1815
{{py:
1916

2017
# name, dtype, c_type
@@ -794,7 +791,6 @@ cdef class StringHashTable(HashTable):
794791
# if ignore_na is False, we also stringify NaN/None/etc.
795792
v = get_c_string(<str>val)
796793
if v == NULL:
797-
PyErr_Clear()
798794
v = get_c_string(<str>repr(val))
799795
vecs[i] = v
800796

pandas/_libs/tslibs/util.pxd

+4-5
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,10 @@ cdef inline const char* get_c_string_buf_and_size(str py_string,
238238
-------
239239
buf : const char*
240240
"""
241-
cdef:
242-
const char *buf
243-
244-
buf = PyUnicode_AsUTF8AndSize(py_string, length)
245-
return buf
241+
try:
242+
return PyUnicode_AsUTF8AndSize(py_string, length)
243+
except UnicodeEncodeError:
244+
return NULL
246245

247246

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

0 commit comments

Comments
 (0)