Skip to content

json_normalize errors if meta fields are integer #32480

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

Closed
joetl opened this issue Mar 6, 2020 · 2 comments
Closed

json_normalize errors if meta fields are integer #32480

joetl opened this issue Mar 6, 2020 · 2 comments
Assignees

Comments

@joetl
Copy link

joetl commented Mar 6, 2020

Code Sample, a copy-pastable example if possible

import pandas as pd

data = [{"person_id": "test", 
         "test_field": 1,  
         "access": [{"step": 1, 
                     "phase":"starting"}, 
                    {"step":2,
                     "phase":"ending"}
                    ]
         }]

df = pd.json_normalize(data,"access",meta=["person_id","test_field"])

print(df)

Problem description

If meta fields are integer we get the below error. json_normalize works fine for string datatype
Traceback (most recent call last):
File "C:/Users/HOME/PycharmProjects/pandas_test/pandas_test.py", line 12, in
df = pd.json_normalize(data,"access",meta=["person_id","test_field"])
File "C:\Users\HOME\Anaconda3\envs\pandas_test\lib\site-packages\pandas\io\json_normalize.py", line 327, in _json_normalize
_recursive_extract(data, record_path, {}, level=0)
File "C:\Users\HOME\Anaconda3\envs\pandas_test\lib\site-packages\pandas\io\json_normalize.py", line 314, in _recursive_extract
meta_val = _pull_field(obj, val[level:])
File "C:\Users\HOME\Anaconda3\envs\pandas_test\lib\site-packages\pandas\io\json_normalize.py", line 246, in _pull_field
f"{js} has non iterable value {result} for path {spec}. "
TypeError: {'person_id': 'test', 'test_field': 1, 'access': [{'step': 1, 'phase': 'starting'}, {'step': 2, 'phase': 'ending'}]} has non iterable value 1 for path ['test_field']. Must be iterable or null.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : AMD64 Family 16 Model 10 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0.post20200210
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@Mxchaeltrxn
Copy link

take

@charlesdong1991
Copy link
Member

charlesdong1991 commented Mar 10, 2020

thanks for the issue!

this is a duplicate issue #31507 and a PR #31524 is underway to fix this, so let's close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants