Skip to content

Commit da84997

Browse files
committed
Address 1st round of feedback
1 parent 5af5d82 commit da84997

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

doc/source/whatsnew/v0.23.5.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,4 @@ Bug Fixes
5252
**I/O**
5353

5454
- Bug in :func:`read_csv` that caused it to raise ``OverflowError`` when trying to use 'inf' as ``na_value`` with integer index column (:issue:`17128`)
55-
- Bug in :func:`json_normalize` that caused it to raise ``TypeError`` when ``record_path`` has a sequence of dicts along its path (:issue:`22706`)
5655
-

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ I/O
763763
- :func:`read_sas()` will correctly parse sas7bdat files with data page types having also bit 7 set (so page type is 128 + 256 = 384) (:issue:`16615`)
764764
- Bug in :meth:`detect_client_encoding` where potential ``IOError`` goes unhandled when importing in a mod_wsgi process due to restricted access to stdout. (:issue:`21552`)
765765
- Bug in :func:`to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`)
766+
- Bug in :func:`json_normalize` that caused it to raise ``TypeError`` when ``record_path`` has a sequence of dicts along its path (:issue:`22706`)
766767

767768
Plotting
768769
^^^^^^^^

pandas/io/json/normalize.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,29 @@ def _pull_field(js, spec):
224224
sep = str(sep)
225225
meta_keys = [sep.join(val) for val in meta]
226226

227-
def _extract(obj, path, seen_meta, level):
228-
recs = _pull_field(obj, path[0])
227+
def _extract(obj, field, seen_meta, level):
228+
"""
229+
Extract field from obj.
230+
The result is stored in `records`, `lengths`, and `meta_vals`.
231+
232+
Parameters
233+
----------
234+
obj : dict
235+
Unserialized JSON object
236+
field : string
237+
The field to extract from obj
238+
seen_meta : dict
239+
The dict of meta values that have been visited
240+
level: int
241+
The current level
242+
"""
243+
recs = _pull_field(obj, field)
229244

230245
# For repeating the metadata later
231246
lengths.append(len(recs))
232247

233248
for val, key in zip(meta, meta_keys):
234-
if level + 1 > len(val):
249+
if level >= len(val):
235250
meta_val = seen_meta[key]
236251
else:
237252
try:
@@ -259,9 +274,9 @@ def _recursive_extract(data, path, seen_meta, level=0):
259274
seen_meta, level=level + 1)
260275
elif isinstance(data, list):
261276
for obj in data:
262-
_extract(obj, path, seen_meta, level)
277+
_extract(obj, path[0], seen_meta, level)
263278
else:
264-
_extract(data, path, seen_meta, level)
279+
_extract(data, path[0], seen_meta, level)
265280

266281
_recursive_extract(data, record_path, {}, level=0)
267282

0 commit comments

Comments
 (0)