Skip to content

Commit b4cab55

Browse files
committed
fix: handle none data in _recursive_extract
1 parent 841ebb1 commit b4cab55

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pandas/io/json/_normalize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ def _pull_records(js: dict[str, Any], spec: list | str) -> list:
490490
meta_keys = [sep.join(val) for val in _meta]
491491

492492
def _recursive_extract(data, path, seen_meta, level: int = 0) -> None:
493+
if data is None:
494+
return
493495
if isinstance(data, dict):
494496
data = [data]
495497
if len(path) > 1:

pandas/tests/io/json/test_normalize.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,29 @@ def test_top_column_with_leading_underscore(self):
582582

583583
tm.assert_frame_equal(result, expected)
584584

585+
def test_column_with_none(self):
586+
# 53719
587+
data = {
588+
"root": [
589+
{
590+
"id": 1,
591+
"nested_field": [{"nested_field_id": 1}],
592+
},
593+
{"id": 2, "nested_field": None},
594+
]
595+
}
596+
result = json_normalize(
597+
data,
598+
record_path=["root", "nested_field"],
599+
)
600+
expected = DataFrame(
601+
{
602+
"nested_field_id": [1],
603+
}
604+
)
605+
606+
tm.assert_frame_equal(result, expected)
607+
585608

586609
class TestNestedToRecord:
587610
def test_flat_stays_flat(self):

0 commit comments

Comments
 (0)