-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Avoids exception when pandas.io.json.json_normalize contains items in… #14505
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
Changes from 2 commits
a560331
050bf60
66b4c83
6130e77
6ac759d
31ca717
e7ac84d
d7fb5bd
096d886
7f5a45c
b793443
1ce6299
47f117d
b088112
60a335e
e544362
c3e25c6
8b80562
eb7bd99
52f31d4
1d95179
093aa82
7f0c4e0
252526c
e1cdc4b
5aaf8fe
8928270
9848837
cc2fdc2
33495bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -792,7 +792,10 @@ def _recursive_extract(data, path, seen_meta, level=0): | |
if level + 1 > len(val): | ||
meta_val = seen_meta[key] | ||
else: | ||
meta_val = _pull_field(obj, val[level:]) | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be a keyword, call it |
||
meta_val = _pull_field(obj, val[level:]) | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use a bare except, list a specific exception |
||
meta_val = np.nan | ||
meta_vals[key].append(meta_val) | ||
|
||
records.extend(recs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,51 @@ def test_nested_flattens(self): | |
|
||
self.assertEqual(result, expected) | ||
|
||
def test_json_normalise_fix(self): | ||
j = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number as a comment |
||
"Trades": [{ | ||
"general": { | ||
"tradeid": 100, | ||
"trade_version": 1, | ||
"stocks": [{ | ||
|
||
"symbol": "AAPL", | ||
"name": "Apple", | ||
"price": "0" | ||
|
||
}, { | ||
|
||
"symbol": "GOOG", | ||
"name": "Google", | ||
"price": "0" | ||
|
||
} | ||
] | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this prob does not pass linting. make sure it does. |
||
}, { | ||
"general": { | ||
"tradeid": 100, | ||
"stocks": [{ | ||
|
||
"symbol": "AAPL", | ||
"name": "Apple", | ||
"price": "0" | ||
|
||
}, { | ||
"symbol": "GOOG", | ||
"name": "Google", | ||
"price": "0" | ||
|
||
} | ||
] | ||
}, | ||
} | ||
] | ||
} | ||
j = json_normalize(data=j['Trades'], record_path=[['general', 'stocks']], | ||
meta=[['general', 'tradeid'], ['general', 'trade_version']]) | ||
self.assertEqual(len(j), 4) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. construct the expected frame and use |
||
|
||
if __name__ == '__main__': | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', | ||
'--pdb-failure', '-s'], exit=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls simplify. a user just wants to know does this issue pertain to them, and a short expl.
make the issue
(:issue:
14505)