Skip to content

Remove Unused Functions from ujson #26198

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 7 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Sparse
Other
^^^^^

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


.. _whatsnew_0.250.contributors:
Expand Down
45 changes: 0 additions & 45 deletions pandas/_libs/src/ujson/python/JSONtoObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
58 changes: 0 additions & 58 deletions pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 0 additions & 12 deletions pandas/_libs/src/ujson/python/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 " \
Expand All @@ -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 */
};

Expand Down
57 changes: 0 additions & 57 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import calendar
import datetime
import decimal
from io import StringIO
import locale
import math
import re
Expand Down Expand Up @@ -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):
Expand Down