Skip to content

Commit 3de7139

Browse files
WillAydjreback
authored andcommitted
Remove Unused Functions from ujson (pandas-dev#26198)
1 parent 444ba64 commit 3de7139

File tree

5 files changed

+1
-173
lines changed

5 files changed

+1
-173
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ Sparse
417417
Other
418418
^^^^^
419419

420-
-
420+
- Removed unused C functions from vendored UltraJSON implementation (:issue:`26198`)
421421

422422

423423
.. _whatsnew_0.250.contributors:

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

-45
Original file line numberDiff line numberDiff line change
@@ -589,48 +589,3 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs) {
589589

590590
return ret;
591591
}
592-
593-
PyObject *JSONFileToObj(PyObject *self, PyObject *args, PyObject *kwargs) {
594-
PyObject *read;
595-
PyObject *string;
596-
PyObject *result;
597-
PyObject *file = NULL;
598-
PyObject *argtuple;
599-
600-
if (!PyArg_ParseTuple(args, "O", &file)) {
601-
return NULL;
602-
}
603-
604-
if (!PyObject_HasAttrString(file, "read")) {
605-
PyErr_Format(PyExc_TypeError, "expected file");
606-
return NULL;
607-
}
608-
609-
read = PyObject_GetAttrString(file, "read");
610-
611-
if (!PyCallable_Check(read)) {
612-
Py_XDECREF(read);
613-
PyErr_Format(PyExc_TypeError, "expected file");
614-
return NULL;
615-
}
616-
617-
string = PyObject_CallObject(read, NULL);
618-
Py_XDECREF(read);
619-
620-
if (string == NULL) {
621-
return NULL;
622-
}
623-
624-
argtuple = PyTuple_Pack(1, string);
625-
626-
result = JSONToObj(self, argtuple, kwargs);
627-
628-
Py_XDECREF(argtuple);
629-
Py_XDECREF(string);
630-
631-
if (result == NULL) {
632-
return NULL;
633-
}
634-
635-
return result;
636-
}

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

-58
Original file line numberDiff line numberDiff line change
@@ -2467,61 +2467,3 @@ PyObject *objToJSON(PyObject *self, PyObject *args, PyObject *kwargs) {
24672467

24682468
return newobj;
24692469
}
2470-
2471-
PyObject *objToJSONFile(PyObject *self, PyObject *args, PyObject *kwargs) {
2472-
PyObject *data;
2473-
PyObject *file;
2474-
PyObject *string;
2475-
PyObject *write;
2476-
PyObject *argtuple;
2477-
2478-
PRINTMARK();
2479-
2480-
if (!PyArg_ParseTuple(args, "OO", &data, &file)) {
2481-
return NULL;
2482-
}
2483-
2484-
if (!PyObject_HasAttrString(file, "write")) {
2485-
PyErr_Format(PyExc_TypeError, "expected file");
2486-
return NULL;
2487-
}
2488-
2489-
write = PyObject_GetAttrString(file, "write");
2490-
2491-
if (!PyCallable_Check(write)) {
2492-
Py_XDECREF(write);
2493-
PyErr_Format(PyExc_TypeError, "expected file");
2494-
return NULL;
2495-
}
2496-
2497-
argtuple = PyTuple_Pack(1, data);
2498-
2499-
string = objToJSON(self, argtuple, kwargs);
2500-
2501-
if (string == NULL) {
2502-
Py_XDECREF(write);
2503-
Py_XDECREF(argtuple);
2504-
return NULL;
2505-
}
2506-
2507-
Py_XDECREF(argtuple);
2508-
2509-
argtuple = PyTuple_Pack(1, string);
2510-
if (argtuple == NULL) {
2511-
Py_XDECREF(write);
2512-
return NULL;
2513-
}
2514-
if (PyObject_CallObject(write, argtuple) == NULL) {
2515-
Py_XDECREF(write);
2516-
Py_XDECREF(argtuple);
2517-
return NULL;
2518-
}
2519-
2520-
Py_XDECREF(write);
2521-
Py_DECREF(argtuple);
2522-
Py_XDECREF(string);
2523-
2524-
PRINTMARK();
2525-
2526-
Py_RETURN_NONE;
2527-
}

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

-12
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ void initObjToJSON(void);
4646
/* JSONToObj */
4747
PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs);
4848

49-
/* objToJSONFile */
50-
PyObject *objToJSONFile(PyObject *self, PyObject *args, PyObject *kwargs);
51-
52-
/* JSONFileToObj */
53-
PyObject *JSONFileToObj(PyObject *self, PyObject *args, PyObject *kwargs);
54-
5549
#define ENCODER_HELP_TEXT \
5650
"Use ensure_ascii=false to output UTF-8. Pass in double_precision to " \
5751
"alter the maximum digit precision of doubles. Set " \
@@ -68,12 +62,6 @@ static PyMethodDef ujsonMethods[] = {
6862
{"loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
6963
"Converts JSON as string to dict object structure. Use precise_float=True "
7064
"to use high precision float decoder."},
71-
{"dump", (PyCFunction)objToJSONFile, METH_VARARGS | METH_KEYWORDS,
72-
"Converts arbitrary object recursively into JSON "
73-
"file. " ENCODER_HELP_TEXT},
74-
{"load", (PyCFunction)JSONFileToObj, METH_VARARGS | METH_KEYWORDS,
75-
"Converts JSON as file to dict object structure. Use precise_float=True "
76-
"to use high precision float decoder."},
7765
{NULL, NULL, 0, NULL} /* Sentinel */
7866
};
7967

pandas/tests/io/json/test_ujson.py

-57
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import calendar
88
import datetime
99
import decimal
10-
from io import StringIO
1110
import locale
1211
import math
1312
import re
@@ -562,62 +561,6 @@ def test_encode_long_conversion(self):
562561
def test_decode_numeric_int_exp(self, int_exp):
563562
assert ujson.decode(int_exp) == json.loads(int_exp)
564563

565-
def test_dump_to_file(self):
566-
f = StringIO()
567-
ujson.dump([1, 2, 3], f)
568-
assert "[1,2,3]" == f.getvalue()
569-
570-
def test_dump_to_file_like(self):
571-
class FileLike:
572-
573-
def __init__(self):
574-
self.bytes = ''
575-
576-
def write(self, data_bytes):
577-
self.bytes += data_bytes
578-
579-
f = FileLike()
580-
ujson.dump([1, 2, 3], f)
581-
assert "[1,2,3]" == f.bytes
582-
583-
def test_dump_file_args_error(self):
584-
with pytest.raises(TypeError):
585-
ujson.dump([], "")
586-
587-
def test_load_file(self):
588-
data = "[1,2,3,4]"
589-
exp_data = [1, 2, 3, 4]
590-
591-
f = StringIO(data)
592-
assert exp_data == ujson.load(f)
593-
594-
f = StringIO(data)
595-
tm.assert_numpy_array_equal(np.array(exp_data),
596-
ujson.load(f, numpy=True))
597-
598-
def test_load_file_like(self):
599-
class FileLike:
600-
601-
def read(self):
602-
try:
603-
self.end
604-
except AttributeError:
605-
self.end = True
606-
return "[1,2,3,4]"
607-
608-
exp_data = [1, 2, 3, 4]
609-
610-
f = FileLike()
611-
assert exp_data == ujson.load(f)
612-
613-
f = FileLike()
614-
tm.assert_numpy_array_equal(np.array(exp_data),
615-
ujson.load(f, numpy=True))
616-
617-
def test_load_file_args_error(self):
618-
with pytest.raises(TypeError):
619-
ujson.load("[]")
620-
621564
def test_loads_non_str_bytes_raises(self):
622565
msg = "Expected 'str' or 'bytes'"
623566
with pytest.raises(TypeError, match=msg):

0 commit comments

Comments
 (0)