Skip to content

Commit d202ead

Browse files
committed
Fix NoneType error when pulling non existent field
If normalizing a jsonstruct a field can be absent due to a schema change.
1 parent facd756 commit d202ead

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ I/O
774774
- Bug in :func:`read_json` where default encoding was not set to ``utf-8`` (:issue:`29565`)
775775
- Bug in :class:`PythonParser` where str and bytes were being mixed when dealing with the decimal field (:issue:`29650`)
776776
- :meth:`read_gbq` now accepts ``progress_bar_type`` to display progress bar while the data downloads. (:issue:`29857`)
777-
-
777+
- Bug in :func:`pandas.io.json.json_normalize` where a change of schema in json could lead to a NoneType error (:issue:`30148`)
778778

779779
Plotting
780780
^^^^^^^^

pandas/io/json/_normalize.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,16 @@ def _recursive_extract(data, path, seen_meta, level=0):
286286
else:
287287
for obj in data:
288288
recs = _pull_field(obj, path[0])
289-
recs = [
290-
nested_to_record(r, sep=sep, max_level=max_level)
291-
if isinstance(r, dict)
292-
else r
293-
for r in recs
294-
]
289+
recs = (
290+
[
291+
nested_to_record(r, sep=sep, max_level=max_level)
292+
if isinstance(r, dict)
293+
else r
294+
for r in recs
295+
]
296+
if recs
297+
else []
298+
)
295299

296300
# For repeating the metadata later
297301
lengths.append(len(recs))

0 commit comments

Comments
 (0)