Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions pandas/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,12 @@ def nested_to_record(ds, prefix="", level=0):
new_d = copy.deepcopy(d)
for k, v in d.items():
# each key gets renamed with prefix
if not isinstance(k, basestring):
k = str(k)
if level == 0:
newkey = str(k)
newkey = k
else:
newkey = prefix + '.' + str(k)
newkey = prefix + '.' + k

# only dicts gets recurse-flattend
# only at level>1 do we rename the rest of the keys
Expand Down
26 changes: 26 additions & 0 deletions pandas/tests/frame/test_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this can go (just the test), don't add a new file in pandas/io/tests/json/test_json_norm.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the second part, but I removed the encoding-line

""""""

from __future__ import (absolute_import, division, print_function)

import pandas.util.testing as tm
import pandas as pd
import json


class TestJSON(tm.TestCase):
testjson = u'''
[{"Ünicøde":0,"sub":{"A":1, "B":2}},
{"Ünicøde":1,"sub":{"A":3, "B":4}}]
'''.encode('utf8')

testdata = {
u'sub.A': [1, 3],
u'sub.B': [2, 4],
u'Ünicøde': [0, 1]
}
testdf = pd.DataFrame(testdata)

def test_json_normalize(self):
df = pd.io.json.json_normalize(json.loads(self.testjson))
tm.assert_frame_equal(df, self.testdf)