Skip to content

Removed Unnecessary Compat Directives from ujson #26211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ npy_int64 get_nat(void) { return NPY_MIN_INT64; }
typedef void *(*PFN_PyTypeToJSON)(JSOBJ obj, JSONTypeContext *ti,
void *outValue, size_t *_outLen);

#if (PY_VERSION_HEX < 0x02050000)
typedef ssize_t Py_ssize_t;
#endif

typedef struct __NpyArrContext {
PyObject *array;
char *dataptr;
Expand Down Expand Up @@ -153,12 +149,7 @@ enum PANDAS_FORMAT { SPLIT, RECORDS, INDEX, COLUMNS, VALUES };

int PdBlock_iterNext(JSOBJ, JSONTypeContext *);

// import_array() compat
#if (PY_VERSION_HEX >= 0x03000000)
void *initObjToJSON(void)
#else
void initObjToJSON(void)
#endif
{
PyObject *mod_pandas;
PyObject *mod_nattype;
Expand Down Expand Up @@ -426,14 +417,12 @@ static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue,
PyObject *obj, *newObj;
obj = (PyObject *)_obj;

#if (PY_VERSION_HEX >= 0x03030000)
if (PyUnicode_IS_COMPACT_ASCII(obj)) {
Py_ssize_t len;
char *data = (char*)PyUnicode_AsUTF8AndSize(obj, &len);
*_outLen = len;
return data;
}
#endif

newObj = PyUnicode_AsUTF8String(obj);

Expand Down Expand Up @@ -720,15 +709,7 @@ int NpyArr_iterNextItem(JSOBJ obj, JSONTypeContext *tc) {

NpyArr_freeItemValue(obj, tc);

#if NPY_API_VERSION < 0x00000007
if (PyArray_ISDATETIME(npyarr->array)) {
PRINTMARK();
GET_TC(tc)
->itemValue = PyArray_ToScalar(npyarr->dataptr, npyarr->array);
} else if (PyArray_ISNUMBER(npyarr->array)) // NOLINT
#else
if (PyArray_ISNUMBER(npyarr->array) || PyArray_ISDATETIME(npyarr->array)) // NOLINT
#endif
if (PyArray_ISNUMBER(npyarr->array) || PyArray_ISDATETIME(npyarr->array))
{
PRINTMARK();
GET_TC(tc)->itemValue = obj;
Expand Down Expand Up @@ -1619,13 +1600,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, JSONObjectEncoder *enc,
type_num = PyArray_TYPE(labels);

for (i = 0; i < num; i++) {
#if NPY_API_VERSION < 0x00000007
if (PyTypeNum_ISDATETIME(type_num)) {
item = PyArray_ToScalar(dataptr, labels);
} else if (PyTypeNum_ISNUMBER(type_num)) // NOLINT
#else
if (PyTypeNum_ISDATETIME(type_num) || PyTypeNum_ISNUMBER(type_num)) // NOLINT
#endif
if (PyTypeNum_ISDATETIME(type_num) || PyTypeNum_ISNUMBER(type_num))
{
item = (PyObject *)labels;
pyenc->npyType = type_num;
Expand Down