Skip to content

BUG: Python Parser skipping over items if BOM present in first element of header #36365

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

Merged
merged 6 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2876,7 +2876,7 @@ def _check_for_bom(self, first_row):
return [new_row] + first_row[1:]

elif len(first_row_bom) > 1:
return [first_row_bom[1:]]
return [first_row_bom[1:]] + first_row[1:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't find this very clear why we would do this - can you try refactoring the code above this to better suit the requirement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I understand
the code block above removes the BOM from the first element of the row and removes the quotes if it was a quoted string. i.e. if it was of the format <BOM><QUOTE>abc<QUOTE>def then it extracts out abcdef

I've tried to refactor it slightly

else:
# First row is just the BOM, so we
# return an empty string.
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/parser/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,12 @@ def test_first_row_bom(all_parsers):
expected = DataFrame(columns=["Head1", "Head2", "Head3"])
tm.assert_frame_equal(result, expected)

# see gh-36343
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a new test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data = """\ufeffHead1 Head2 Head3"""

result = parser.read_csv(StringIO(data), delimiter="\t")
tm.assert_frame_equal(result, expected)


def test_integer_precision(all_parsers):
# Gh 7072
Expand Down