Skip to content

BUG: read_excel skips single-column empty rows #40214

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 4 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ I/O
- :meth:`read_sql` returned an empty generator if ``chunksize`` was no-zero and the query returned no results. Now returns a generator with a single empty dataframe (:issue:`34411`)
- Bug in :func:`read_hdf` returning unexpected records when filtering on categorical string columns using ``where`` parameter (:issue:`39189`)
- Bug in :func:`read_sas` raising ``ValueError`` when ``datetimes`` were null (:issue:`39725`)
- Bug in :func:`read_excel` dropping empty values from single-column spreadsheets (:issue:`39808`)

Period
^^^^^^
Expand Down
1 change: 1 addition & 0 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def parse(
skiprows=skiprows,
nrows=nrows,
na_values=na_values,
skip_blank_lines=False,
Copy link
Member

Choose a reason for hiding this comment

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

Why not expose this parameter in read_excel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We tried that (#40095) but the behaviour when skip_blank_lines=True isn't very useful---it only skips empty spreadsheet rows if the entire spreadsheet is contained in column A. The original intent of skip_blank_lines was to skip \n lines in CSV files, but not lines with empty data elements such as ""\n or ,,,,\n, so there isn't an equivalent feature for spreadsheets.

Copy link
Member

@gfyoung gfyoung Mar 4, 2021

Choose a reason for hiding this comment

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

I see. Can we make a comment about this and reference your original PR?

Copy link
Contributor Author

@ahawryluk ahawryluk Mar 4, 2021

Choose a reason for hiding this comment

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

For sure. Do you mean an inline comment in the code, or in the description of this pull request?

parse_dates=parse_dates,
date_parser=date_parser,
thousands=thousands,
Expand Down
Binary file added pandas/tests/io/data/excel/one_col_blank_line.ods
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,13 @@ def test_no_header_with_list_index_col(self, read_ext):
)
tm.assert_frame_equal(expected, result)

def test_one_col_noskip_blank_line(self, read_ext):
file_name = "one_col_blank_line" + read_ext
data = [0.5, np.nan, 1, 2]
expected = DataFrame(data, columns=["numbers"])
result = pd.read_excel(file_name)
tm.assert_frame_equal(expected, result)


class TestExcelFileRead:
@pytest.fixture(autouse=True)
Expand Down