Skip to content

Commit 9213f9f

Browse files
committed
Address 1st round of feedback
1 parent dfa6579 commit 9213f9f

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-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
@@ -759,6 +759,7 @@ I/O
759759
- :func:`read_sas()` will correctly parse sas7bdat files with many columns (:issue:`22628`)
760760
- :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`)
761761
- 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`)
762+
- Bug in :func:`json_normalize` that caused it to raise ``TypeError`` when ``record_path`` has a sequence of dicts along its path (:issue:`22706`)
762763

763764
Plotting
764765
^^^^^^^^

pandas/io/json/normalize.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,28 @@ 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 (the result is stored in `records`, `lengths`, and `meta_vals`).
230+
231+
Parameters
232+
----------
233+
obj : dict
234+
Unserialized JSON object
235+
field : string
236+
The field to extract from obj
237+
seen_meta : dict
238+
The dict of meta values that have been visited
239+
level: int
240+
The current level
241+
"""
242+
recs = _pull_field(obj, field)
229243

230244
# For repeating the metadata later
231245
lengths.append(len(recs))
232246

233247
for val, key in zip(meta, meta_keys):
234-
if level + 1 > len(val):
248+
if level >= len(val):
235249
meta_val = seen_meta[key]
236250
else:
237251
try:
@@ -259,9 +273,9 @@ def _recursive_extract(data, path, seen_meta, level=0):
259273
seen_meta, level=level + 1)
260274
elif isinstance(data, list):
261275
for obj in data:
262-
_extract(obj, path, seen_meta, level)
276+
_extract(obj, path[0], seen_meta, level)
263277
else:
264-
_extract(data, path, seen_meta, level)
278+
_extract(data, path[0], seen_meta, level)
265279

266280
_recursive_extract(data, record_path, {}, level=0)
267281

0 commit comments

Comments
 (0)