Skip to content

TYP: check_untyped_defs io.json._normalize #30573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions pandas/io/json/_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def nested_to_record(
def _json_normalize(
data: Union[Dict, List[Dict]],
record_path: Optional[Union[str, List]] = None,
meta: Optional[Union[str, List]] = None,
meta: Optional[Union[str, List[Union[str, List[str]]]]] = None,
meta_prefix: Optional[str] = None,
record_prefix: Optional[str] = None,
errors: Optional[str] = "raise",
Expand Down Expand Up @@ -265,21 +265,21 @@ def _pull_field(js, spec):
elif not isinstance(meta, list):
meta = [meta]

meta = [m if isinstance(m, list) else [m] for m in meta]
_meta = [m if isinstance(m, list) else [m] for m in meta]

# Disastrously inefficient for now
records: List = []
lengths = []

meta_vals: DefaultDict = defaultdict(list)
meta_keys = [sep.join(val) for val in meta]
meta_keys = [sep.join(val) for val in _meta]

def _recursive_extract(data, path, seen_meta, level=0):
if isinstance(data, dict):
data = [data]
if len(path) > 1:
for obj in data:
for val, key in zip(meta, meta_keys):
for val, key in zip(_meta, meta_keys):
if level + 1 == len(val):
seen_meta[key] = _pull_field(obj, val[-1])

Expand All @@ -296,7 +296,7 @@ def _recursive_extract(data, path, seen_meta, level=0):

# For repeating the metadata later
lengths.append(len(recs))
for val, key in zip(meta, meta_keys):
for val, key in zip(_meta, meta_keys):
if level + 1 > len(val):
meta_val = seen_meta[key]
else:
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ check_untyped_defs=False
[mypy-pandas.io.json._json]
check_untyped_defs=False

[mypy-pandas.io.json._normalize]
check_untyped_defs=False

[mypy-pandas.io.json._table_schema]
check_untyped_defs=False

Expand Down