diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 3e00ec9cbb742..49b8c49573b6a 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -417,7 +417,7 @@ Sparse Other ^^^^^ -- +- Removed unused C functions from vendored UltraJSON implementation (:issue:`26198`) .. _whatsnew_0.250.contributors: diff --git a/pandas/_libs/src/ujson/python/JSONtoObj.c b/pandas/_libs/src/ujson/python/JSONtoObj.c index 7fd5fb4eb8e83..7a2e5a584443a 100644 --- a/pandas/_libs/src/ujson/python/JSONtoObj.c +++ b/pandas/_libs/src/ujson/python/JSONtoObj.c @@ -589,48 +589,3 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs) { return ret; } - -PyObject *JSONFileToObj(PyObject *self, PyObject *args, PyObject *kwargs) { - PyObject *read; - PyObject *string; - PyObject *result; - PyObject *file = NULL; - PyObject *argtuple; - - if (!PyArg_ParseTuple(args, "O", &file)) { - return NULL; - } - - if (!PyObject_HasAttrString(file, "read")) { - PyErr_Format(PyExc_TypeError, "expected file"); - return NULL; - } - - read = PyObject_GetAttrString(file, "read"); - - if (!PyCallable_Check(read)) { - Py_XDECREF(read); - PyErr_Format(PyExc_TypeError, "expected file"); - return NULL; - } - - string = PyObject_CallObject(read, NULL); - Py_XDECREF(read); - - if (string == NULL) { - return NULL; - } - - argtuple = PyTuple_Pack(1, string); - - result = JSONToObj(self, argtuple, kwargs); - - Py_XDECREF(argtuple); - Py_XDECREF(string); - - if (result == NULL) { - return NULL; - } - - return result; -} diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 20b11a26afd15..36bf69c50217f 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -2467,61 +2467,3 @@ PyObject *objToJSON(PyObject *self, PyObject *args, PyObject *kwargs) { return newobj; } - -PyObject *objToJSONFile(PyObject *self, PyObject *args, PyObject *kwargs) { - PyObject *data; - PyObject *file; - PyObject *string; - PyObject *write; - PyObject *argtuple; - - PRINTMARK(); - - if (!PyArg_ParseTuple(args, "OO", &data, &file)) { - return NULL; - } - - if (!PyObject_HasAttrString(file, "write")) { - PyErr_Format(PyExc_TypeError, "expected file"); - return NULL; - } - - write = PyObject_GetAttrString(file, "write"); - - if (!PyCallable_Check(write)) { - Py_XDECREF(write); - PyErr_Format(PyExc_TypeError, "expected file"); - return NULL; - } - - argtuple = PyTuple_Pack(1, data); - - string = objToJSON(self, argtuple, kwargs); - - if (string == NULL) { - Py_XDECREF(write); - Py_XDECREF(argtuple); - return NULL; - } - - Py_XDECREF(argtuple); - - argtuple = PyTuple_Pack(1, string); - if (argtuple == NULL) { - Py_XDECREF(write); - return NULL; - } - if (PyObject_CallObject(write, argtuple) == NULL) { - Py_XDECREF(write); - Py_XDECREF(argtuple); - return NULL; - } - - Py_XDECREF(write); - Py_DECREF(argtuple); - Py_XDECREF(string); - - PRINTMARK(); - - Py_RETURN_NONE; -} diff --git a/pandas/_libs/src/ujson/python/ujson.c b/pandas/_libs/src/ujson/python/ujson.c index d8ccb9f9703cf..39320d73d0cab 100644 --- a/pandas/_libs/src/ujson/python/ujson.c +++ b/pandas/_libs/src/ujson/python/ujson.c @@ -46,12 +46,6 @@ void initObjToJSON(void); /* JSONToObj */ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs); -/* objToJSONFile */ -PyObject *objToJSONFile(PyObject *self, PyObject *args, PyObject *kwargs); - -/* JSONFileToObj */ -PyObject *JSONFileToObj(PyObject *self, PyObject *args, PyObject *kwargs); - #define ENCODER_HELP_TEXT \ "Use ensure_ascii=false to output UTF-8. Pass in double_precision to " \ "alter the maximum digit precision of doubles. Set " \ @@ -68,12 +62,6 @@ static PyMethodDef ujsonMethods[] = { {"loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as string to dict object structure. Use precise_float=True " "to use high precision float decoder."}, - {"dump", (PyCFunction)objToJSONFile, METH_VARARGS | METH_KEYWORDS, - "Converts arbitrary object recursively into JSON " - "file. " ENCODER_HELP_TEXT}, - {"load", (PyCFunction)JSONFileToObj, METH_VARARGS | METH_KEYWORDS, - "Converts JSON as file to dict object structure. Use precise_float=True " - "to use high precision float decoder."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index bd0dc63c02626..21657544ef3df 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -7,7 +7,6 @@ import calendar import datetime import decimal -from io import StringIO import locale import math import re @@ -562,62 +561,6 @@ def test_encode_long_conversion(self): def test_decode_numeric_int_exp(self, int_exp): assert ujson.decode(int_exp) == json.loads(int_exp) - def test_dump_to_file(self): - f = StringIO() - ujson.dump([1, 2, 3], f) - assert "[1,2,3]" == f.getvalue() - - def test_dump_to_file_like(self): - class FileLike: - - def __init__(self): - self.bytes = '' - - def write(self, data_bytes): - self.bytes += data_bytes - - f = FileLike() - ujson.dump([1, 2, 3], f) - assert "[1,2,3]" == f.bytes - - def test_dump_file_args_error(self): - with pytest.raises(TypeError): - ujson.dump([], "") - - def test_load_file(self): - data = "[1,2,3,4]" - exp_data = [1, 2, 3, 4] - - f = StringIO(data) - assert exp_data == ujson.load(f) - - f = StringIO(data) - tm.assert_numpy_array_equal(np.array(exp_data), - ujson.load(f, numpy=True)) - - def test_load_file_like(self): - class FileLike: - - def read(self): - try: - self.end - except AttributeError: - self.end = True - return "[1,2,3,4]" - - exp_data = [1, 2, 3, 4] - - f = FileLike() - assert exp_data == ujson.load(f) - - f = FileLike() - tm.assert_numpy_array_equal(np.array(exp_data), - ujson.load(f, numpy=True)) - - def test_load_file_args_error(self): - with pytest.raises(TypeError): - ujson.load("[]") - def test_loads_non_str_bytes_raises(self): msg = "Expected 'str' or 'bytes'" with pytest.raises(TypeError, match=msg):