-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: read_excel failed with empty rows after MultiIndex header #40649
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 all commits
2d47483
d9f084e
bb21aac
0978a9d
92c4232
677f8b7
47b2c2b
bb0fef0
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 |
---|---|---|
|
@@ -551,7 +551,11 @@ def parse( | |
header_name, _ = pop_header_name(data[row], index_col) | ||
header_names.append(header_name) | ||
|
||
has_index_names = is_list_like(header) and len(header) > 1 | ||
# If there is a MultiIndex header and an index then there is also | ||
# a row containing just the index name(s) | ||
has_index_names = ( | ||
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 add a comment here on what the inference rules are |
||
is_list_like(header) and len(header) > 1 and index_col is not None | ||
ahawryluk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
if is_list_like(index_col): | ||
# Forward fill values for MultiIndex index. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -389,6 +389,17 @@ def test_header_multi_index_common_format_malformed3(all_parsers): | |||||
tm.assert_frame_equal(expected, result) | ||||||
|
||||||
|
||||||
def test_header_multi_index_blank_line(all_parsers): | ||||||
dsaxton marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# GH 40442 | ||||||
parser = all_parsers | ||||||
data = [[None, None], [1, 2], [3, 4]] | ||||||
columns = MultiIndex.from_tuples([("a", "A"), ("b", "B")]) | ||||||
expected = DataFrame(data, columns=columns) | ||||||
data = "a,b\nA,B\n,\n1,2\n3,4" | ||||||
result = parser.read_csv(StringIO(data), header=[0, 1]) | ||||||
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. what happens with 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, these two tests both have pandas/pandas/tests/io/parser/test_header.py Line 126 in 526d52f
pandas/pandas/tests/io/parser/test_header.py Line 219 in 526d52f
|
||||||
tm.assert_frame_equal(expected, result) | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize( | ||||||
"data,header", [("1,2,3\n4,5,6", None), ("foo,bar,baz\n1,2,3\n4,5,6", 0)] | ||||||
) | ||||||
|
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.
can you add a similar comment to below (e.g. for future readers what are the inference rules)