From dcf4ff9891fc01fdc15eea965e307357aceb712d Mon Sep 17 00:00:00 2001 From: Kieran O'Mahony Date: Thu, 18 Jul 2013 12:44:18 +1000 Subject: [PATCH] BUG: fix ujson handling of new series object --- pandas/io/tests/test_json/test_ujson.py | 1 - pandas/src/ujson/python/objToJSON.c | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/tests/test_json/test_ujson.py b/pandas/io/tests/test_json/test_ujson.py index 4ffbc499f17c2..19c482d8b3590 100644 --- a/pandas/io/tests/test_json/test_ujson.py +++ b/pandas/io/tests/test_json/test_ujson.py @@ -1150,7 +1150,6 @@ def testSeries(self): s = Series([10, 20, 30, 40, 50, 60], name="series", index=[6,7,8,9,10,15]) s.sort() - import pdb; pdb.set_trace() # column indexed outp = Series(ujson.decode(ujson.encode(s))) outp.sort() diff --git a/pandas/src/ujson/python/objToJSON.c b/pandas/src/ujson/python/objToJSON.c index 89d3c203fbb7d..06f5fbb5bc0d9 100644 --- a/pandas/src/ujson/python/objToJSON.c +++ b/pandas/src/ujson/python/objToJSON.c @@ -1387,11 +1387,13 @@ void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc) return; } + pc->newObj = PyObject_GetAttrString(obj, "values"); + if (enc->outputFormat == INDEX || enc->outputFormat == COLUMNS) { PRINTMARK(); tc->type = JT_OBJECT; - pc->columnLabelsLen = PyArray_SIZE(obj); + pc->columnLabelsLen = PyArray_DIM(pc->newObj, 0); pc->columnLabels = NpyArr_encodeLabels((PyArrayObject*) PyObject_GetAttrString(obj, "index"), (JSONObjectEncoder*) enc, pc->columnLabelsLen); if (!pc->columnLabels) { @@ -1403,7 +1405,6 @@ void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc) PRINTMARK(); tc->type = JT_ARRAY; } - pc->newObj = PyObject_GetAttrString(obj, "values"); pc->iterBegin = NpyArr_iterBegin; pc->iterEnd = NpyArr_iterEnd; pc->iterNext = NpyArr_iterNext;