Skip to content

Commit e24d9e5

Browse files
WillAydjreback
authored andcommitted
Removed PyString refs from extension modules (#28322)
* Removed PyString refs from extension modules * Reverted macro
1 parent 6b23fb8 commit e24d9e5

File tree

4 files changed

+3
-20
lines changed

4 files changed

+3
-20
lines changed

pandas/_libs/src/parse_helper.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ int to_double(char *item, double *p_value, char sci, char decimal,
2525
return (error == 0) && (!*p_end);
2626
}
2727

28-
#if PY_VERSION_HEX < 0x02060000
29-
#define PyBytes_Check PyString_Check
30-
#define PyBytes_AS_STRING PyString_AS_STRING
31-
#endif // PY_VERSION_HEX
32-
3328
int floatify(PyObject *str, double *result, int *maybe_int) {
3429
int status;
3530
char *data;

pandas/_libs/src/ujson/python/objToJSON.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static void *PyFloatToDOUBLE(JSOBJ _obj, JSONTypeContext *tc, void *outValue,
435435
return NULL;
436436
}
437437

438-
static void *PyStringToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue,
438+
static void *PyBytesToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue,
439439
size_t *_outLen) {
440440
PyObject *obj = (PyObject *)_obj;
441441
*_outLen = PyBytes_GET_SIZE(obj);
@@ -1869,7 +1869,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
18691869
return;
18701870
} else if (PyBytes_Check(obj)) {
18711871
PRINTMARK();
1872-
pc->PyTypeToJSON = PyStringToUTF8;
1872+
pc->PyTypeToJSON = PyBytesToUTF8;
18731873
tc->type = JT_UTF8;
18741874
return;
18751875
} else if (PyUnicode_Check(obj)) {

pandas/_libs/tslibs/util.pxd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ from cpython cimport PyTypeObject
44
cdef extern from *:
55
"""
66
PyObject* char_to_string(const char* data) {
7-
#if PY_VERSION_HEX >= 0x03000000
87
return PyUnicode_FromString(data);
9-
#else
10-
return PyString_FromString(data);
11-
#endif
128
}
139
"""
1410
object char_to_string(const char* data)
@@ -18,7 +14,6 @@ cdef extern from "Python.h":
1814
# Note: importing extern-style allows us to declare these as nogil
1915
# functions, whereas `from cpython cimport` does not.
2016
bint PyUnicode_Check(object obj) nogil
21-
bint PyString_Check(object obj) nogil
2217
bint PyBool_Check(object obj) nogil
2318
bint PyFloat_Check(object obj) nogil
2419
bint PyComplex_Check(object obj) nogil

pandas/_libs/writers.pyx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ from cython import Py_ssize_t
33

44
from cpython cimport PyBytes_GET_SIZE, PyUnicode_GET_SIZE
55

6-
try:
7-
from cpython cimport PyString_GET_SIZE
8-
except ImportError:
9-
from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE
10-
116
import numpy as np
127
from numpy cimport ndarray, uint8_t
138

@@ -126,11 +121,9 @@ def max_len_string_array(pandas_string[:] arr) -> Py_ssize_t:
126121
for i in range(length):
127122
val = arr[i]
128123
if isinstance(val, str):
129-
l = PyString_GET_SIZE(val)
124+
l = PyUnicode_GET_SIZE(val)
130125
elif isinstance(val, bytes):
131126
l = PyBytes_GET_SIZE(val)
132-
elif isinstance(val, unicode):
133-
l = PyUnicode_GET_SIZE(val)
134127

135128
if l > m:
136129
m = l

0 commit comments

Comments
 (0)