-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
json_normalize raises TypeError exception #22706
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
Comments
Thanks for the report - investigation and PRs are always welcome! |
If When Do we assume that
I prefer (2). Let me know what you think. I can create a PR. |
@WillAyd : What do you think of the proposed fix? I'll create a PR if you think it's the right thing to do. |
The docstring claims that either a dict or list of dicts is allowed. The only example with a dict doesn't really do any normalization though:
I'm inclined to do whatever is easiest to maintain in the long-run, though it's not clear what that is in this case. |
I don't think we should assume that it is always a list. In my mind the behavior for In [6]: json_normalize({'foo': 1, 'bar': 2, 'baz': 3})
Out[6]:
bar baz foo
0 2 3 1
In [7]: json_normalize([{'foo': 1, 'bar': 2, 'baz': 3}])
Out[7]:
bar baz foo
0 2 3 1 So I would assume the following to also be equivalent (though currently failing) >>> json_normalize({'info': {'phones': {'foo': 1, 'bar': 2, 'baz': 3}}}, record_path=['info', 'phones'])
>>> json_normalize({'info': {'phones': [{'foo': 1, 'bar': 2, 'baz': 3}]}}, record_path=['info', 'phones']) |
To be clear, I asked about I agree with @WillAyd that the list assumption inside def _extract(data, path, seen_meta, level):
for obj in data: # the body of else clause at L237
...
def _recursive_extract(data, path, seen_meta, level=0):
if len(path) > 1:
# unchanged
else:
if isinstance(data, list):
for obj in data: # similar to the current version
_extract(obj, path, seen_meta, level)
else:
_extract(data, path, seen_meta, level) # this is new to deal with non-list data Note that the current version is def _recursive_extract(data, path, seen_meta, level=0):
if len(path) > 1:
# unchanged
else:
for obj in data:
_extract(obj, path, seen_meta, level) which raises exception when |
@vuminhle feel free to submit a PR for code review |
…uence of dicts along its path pandas-dev#22706
…uence of dicts along its path pandas-dev#22706
…uence of dicts along its path pandas-dev#22706
Code Sample, a copy-pastable example if possible
Problem description
The above code throws
TypeError
exception:Expected Output
Output of
pd.show_versions()
pandas: 0.23.4
pytest: 3.6.2
pip: 18.0
setuptools: 40.2.0
Cython: None
numpy: 1.14.5
scipy: None
pyarrow: None
xarray: None
IPython: 6.3.1
sphinx: 1.5.5
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: