BUG: pd.json_normalize has inconsistent validation for non-string keys - accepts integers in some parameter combinations but rejects in others (original) (raw)
Pandas version checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd data = [{"a": 1, 12: "meta_value", "nested": [{"b": 2}]}]
This works - integer as meta
pd.json_normalize(data, meta=[12])
But this fails - integer as meta (with record_path)
pd.json_normalize(data, record_path=["nested"], meta=[12])
Issue Description
pd.json_normalize exhibits inconsistent behavior when using integer keys in the meta parameter:
meta=[12] (without record_path) - WORKS
record_path=["nested"], meta=[12] - FAILS with TypeError: sequence item 0: expected str instance, int found
Expected Behavior
This should either be consistently supported or consistently rejected.
Installed Versions
Replace this line with the output of pd.show_versions()