-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix json_normalize throwing TypeError (#21536) #21540
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 4 commits
cc4d5b2
b6a4dc5
7aaa71d
30aab15
e28e0c7
b0d3a86
55e1022
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 |
---|---|---|
|
@@ -123,6 +123,12 @@ def test_simple_normalize_with_separator(self, deep_nested): | |
'country', 'states_name']).sort_values() | ||
assert result.columns.sort_values().equals(expected) | ||
|
||
def test_value_array_record_prefix(self): | ||
# GH 21536 | ||
result = json_normalize({'A': [1, 2]}, 'A', record_prefix='Prefix.') | ||
expected = DataFrame([[1], [2]], columns=['Prefix.0']) | ||
tm.assert_frame_equal(result.reindex_like(expected), expected) | ||
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 think 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. Yes. Don't need it. I followed the code in 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. Nope not for test functions. I was referring to the docstring for json_normalize 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. Ah okay. Done. Thanks. |
||
|
||
def test_more_deeply_nested(self, deep_nested): | ||
|
||
result = json_normalize(deep_nested, ['states', 'cities'], | ||
|
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.
use double backticks on
record_prefix
andTypeError
Uh oh!
There was an error while loading. Please reload this page.
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.
isn't the issue that this is for non-string columns? say this instead, the fact that it raised the
TypeError
is the bug hereThere 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.
Will change to double backticks.
The issue is not because the column is non-string; it is because the array contains values (i.e., not objects or arrays). Suggestions are welcome.
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.
how so? before concatting integers and strings would fail.
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 misunderstood. When you mentioned columns, I thought they were the data columns, not the column names. Yes. The bug is caused by concatenating non-string column names, which happens when we pass an array of values (integers, strings, etc.). I can't think of other paths to trigger the bug.
My note explains how one can reproduce the bug. Looks like you want it to describe the reason.
I'm fine with either. How about this?
json_normalize
that caused it to incorrectly raise an error when concatenating non-string columns (:issue:21536
)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.
closer, though a user won't know what concatenating is (in this context), maybe just say something like
bug in formatting the
record_prefix
with integer columnsThere 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.
json_normalize
when formatting therecord_prefix
with integer columns (:issue:21536
)