-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: non-iterable value in meta raise error in json_normalize #31524
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 11 commits
7e461a1
1314059
8bcb313
24c3ede
dea38f2
cd9e7ac
e5e912b
2d21d1e
fcb4b80
8ec4450
a33d05c
6bedc52
1f0f3bc
ce81951
5de348c
3c38c48
130d71b
3ef920f
0b46239
f25a4f4
6eee937
d4d9218
a23eb2d
4c5d61b
9726014
67a43fe
392e3d1
011dbb0
3e74a3a
9476af7
c399983
6165467
7a20b8c
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 |
---|---|---|
|
@@ -749,3 +749,13 @@ def test_series_non_zero_index(self): | |
} | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_meta_non_iterable(self): | ||
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. can you move this near the other test 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. moved! and wait for @WillAyd comment on the other one |
||
# GH 31507 | ||
data = """[{"id": 99, "data": [{"one": 1, "two": 2}]}]""" | ||
|
||
result = json_normalize(json.loads(data), record_path=["data"], meta=["id"]) | ||
expected_values = [[1, 2, "99"]] | ||
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. The expected value here should be |
||
columns = ["one", "two", "id"] | ||
expected = DataFrame(expected_values, columns=columns) | ||
tm.assert_frame_equal(result, expected) |
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.
this is a code smell to add this. so it seems that result can be null, iterabe, or a scalar? if its a scalar what is the return value here?
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.
you mean
[99]
? then will still return 99i think this
Iterable
should only restrict if specifyingrecord_path
, but not formeta
? Am I right about the behaviour here @WillAyd ?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.
I do agree that this is getting a little strange, especially since there is inspection of
meta
on line 273 of the same module and we are essentially repeating that here with a boolean indicator being manually supplied@charlesdong1991 do you see a way to more logically order this function so we don't have to use this bool indicator?
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.
thanks for your reply! @WillAyd
I will think about it a bit, i feel the patch for that
Iterable
in this_pull_field
has code smell a bit because it is used for two cases which have different requirementsThere 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.
i just take a look again at the current codebase, seems that line 273 and onwards you referred is to validate/transform the key which is assigned to
meta
not the value the key associated with, in this case,key
isid
(and we could either specify it as[id]
orid
or more complex cases with nested list, and this part of code will deal with it), however, the code in_pull_field
is to pull the value out, and in this case, the value is99
, and forrecord_path
the value should be anIterable
, while formeta
it does not necessarily be the case, and therefore I think the patch added to check the type should only work for values of which the element ofrecord_path
point to, not formeta
, maybe I miss some functionalities of either of them? @WillAyd @jrebackThere 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.
@charlesdong1991 does splitting this into separate functions for record_path vs meta and just using this as a base for those functions make things cleaner?