Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 4 deletions pandas/io/json/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _pull_field(js, spec):

return result

if isinstance(data, list) and len(data) is 0:
if isinstance(data, list) and not data:
return DataFrame()

# A bit of a hackjob
Expand All @@ -207,9 +207,7 @@ def _pull_field(js, spec):
elif not isinstance(meta, list):
meta = [meta]

for i, x in enumerate(meta):
if not isinstance(x, list):
meta[i] = [x]
meta = [m if isinstance(m, list) else [m] for m in meta]

# Disastrously inefficient for now
records = []
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/io/json/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ def test_meta_name_conflict(self):
for val in ['metafoo', 'metabar', 'foo', 'bar']:
assert val in result

def test_meta_parameter_not_modified(self):
data = [{'foo': 'hello',
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add the issue number here

'bar': 'there',
'data': [{'foo': 'something', 'bar': 'else'},
{'foo': 'something2', 'bar': 'else2'}]}]

COLUMNS = ['foo', 'bar']
result = json_normalize(data, 'data', meta=COLUMNS,
meta_prefix='meta')

assert COLUMNS == ['foo', 'bar']
for val in ['metafoo', 'metabar', 'foo', 'bar']:
assert val in result

def test_record_prefix(self, state_data):
result = json_normalize(state_data[0], 'counties')
expected = DataFrame(state_data[0]['counties'])
Expand Down