Skip to content

Commit 45bbffa

Browse files
committed
BUG: fix CRLF and kludge around datetime64 nanosecond JSON encoding issues per #1263
1 parent 73763af commit 45bbffa

File tree

9 files changed

+5509
-5465
lines changed

9 files changed

+5509
-5465
lines changed

pandas/src/ujson/lib/ultrajson.h

+301-301
Large diffs are not rendered by default.

pandas/src/ujson/lib/ultrajsondec.c

+837-837
Large diffs are not rendered by default.

pandas/src/ujson/lib/ultrajsonenc.c

+858-858
Large diffs are not rendered by default.

pandas/src/ujson/python/JSONtoObj.c

+650-650
Large diffs are not rendered by default.

pandas/src/ujson/python/objToJSON.c

+1,634-1,604
Large diffs are not rendered by default.

pandas/src/ujson/python/ujson.c

+41-41
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
#include <Python.h>
2-
#include "version.h"
3-
4-
/* objToJSON */
5-
PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs);
6-
void initObjToJSON(void);
7-
8-
/* JSONToObj */
9-
PyObject* JSONToObj(PyObject* self, PyObject *args, PyObject *kwargs);
10-
11-
/* objToJSONFile */
12-
PyObject* objToJSONFile(PyObject* self, PyObject *args, PyObject *kwargs);
13-
14-
/* JSONFileToObj */
15-
PyObject* JSONFileToObj(PyObject* self, PyObject *args, PyObject *kwargs);
16-
17-
18-
static PyMethodDef ujsonMethods[] = {
19-
{"encode", (PyCFunction) objToJSON, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursivly into JSON. Use ensure_ascii=false to output UTF-8. Pass in double_precision to alter the maximum digit precision with doubles"},
20-
{"decode", (PyCFunction) JSONToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as string to dict object structure"},
21-
{"dumps", (PyCFunction) objToJSON, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursivly into JSON. Use ensure_ascii=false to output UTF-8"},
22-
{"loads", (PyCFunction) JSONToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as string to dict object structure"},
23-
{"dump", (PyCFunction) objToJSONFile, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursively into JSON file. Use ensure_ascii=false to output UTF-8"},
24-
{"load", (PyCFunction) JSONFileToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as file to dict object structure"},
25-
{NULL, NULL, 0, NULL} /* Sentinel */
26-
};
27-
28-
29-
30-
PyMODINIT_FUNC
31-
init_ujson(void)
32-
{
33-
PyObject *module;
34-
PyObject *version_string;
35-
36-
initObjToJSON();
37-
module = Py_InitModule("_ujson", ujsonMethods);
38-
39-
version_string = PyString_FromString (UJSON_VERSION);
40-
PyModule_AddObject (module, "__version__", version_string);
41-
}
1+
#include <Python.h>
2+
#include "version.h"
3+
4+
/* objToJSON */
5+
PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs);
6+
void initObjToJSON(void);
7+
8+
/* JSONToObj */
9+
PyObject* JSONToObj(PyObject* self, PyObject *args, PyObject *kwargs);
10+
11+
/* objToJSONFile */
12+
PyObject* objToJSONFile(PyObject* self, PyObject *args, PyObject *kwargs);
13+
14+
/* JSONFileToObj */
15+
PyObject* JSONFileToObj(PyObject* self, PyObject *args, PyObject *kwargs);
16+
17+
18+
static PyMethodDef ujsonMethods[] = {
19+
{"encode", (PyCFunction) objToJSON, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursivly into JSON. Use ensure_ascii=false to output UTF-8. Pass in double_precision to alter the maximum digit precision with doubles"},
20+
{"decode", (PyCFunction) JSONToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as string to dict object structure"},
21+
{"dumps", (PyCFunction) objToJSON, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursivly into JSON. Use ensure_ascii=false to output UTF-8"},
22+
{"loads", (PyCFunction) JSONToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as string to dict object structure"},
23+
{"dump", (PyCFunction) objToJSONFile, METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursively into JSON file. Use ensure_ascii=false to output UTF-8"},
24+
{"load", (PyCFunction) JSONFileToObj, METH_VARARGS | METH_KEYWORDS, "Converts JSON as file to dict object structure"},
25+
{NULL, NULL, 0, NULL} /* Sentinel */
26+
};
27+
28+
29+
30+
PyMODINIT_FUNC
31+
init_ujson(void)
32+
{
33+
PyObject *module;
34+
PyObject *version_string;
35+
36+
initObjToJSON();
37+
module = Py_InitModule("_ujson", ujsonMethods);
38+
39+
version_string = PyString_FromString (UJSON_VERSION);
40+
PyModule_AddObject (module, "__version__", version_string);
41+
}

pandas/tests/test_frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2005,9 +2005,8 @@ def _check_orient(df, orient, dtype=None, numpy=True):
20052005
unser = DataFrame.from_json(dfjson, orient=orient, dtype=dtype,
20062006
numpy=numpy)
20072007
unser = unser.sort()
2008-
mktimestamp = datetime.fromtimestamp
20092008
if df.index.dtype.type == np.datetime64:
2010-
unser.index = [mktimestamp(float(d)) for d in unser.index]
2009+
unser.index = DatetimeIndex(unser.index.values.astype('i8'))
20112010
if orient == "records":
20122011
# index is not captured in this orientation
20132012
assert_almost_equal(df.values, unser.values)

pandas/tests/test_series.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ def _check_orient(series, orient, dtype=None, numpy=True):
326326
orient=orient, numpy=numpy, dtype=dtype)
327327
unser = unser.sort_index()
328328
if series.index.dtype.type == np.datetime64:
329-
mktimestamp = date.fromtimestamp
330-
unser.index = [mktimestamp(float(d)) for d in unser.index]
329+
unser.index = DatetimeIndex(unser.index.values.astype('i8'))
331330
if orient == "records" or orient == "values":
332331
assert_almost_equal(series.values, unser.values)
333332
else:

0 commit comments

Comments
 (0)