Skip to content
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

Fix indices when reading Excel files in parallel #2526

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions modin/engines/base/io/text/excel_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _read(cls, io, **kwargs):
# close only if it were us who opened the object
io_file.close()

pandas_kw = dict(kwargs) # preserve original kwargs
with ZipFile(io) as z:
from io import BytesIO

Expand Down Expand Up @@ -129,6 +130,13 @@ def _read(cls, io, **kwargs):
# Remove column names that are specified as `index_col`
if index_col is not None:
column_names = column_names.drop(column_names[index_col])

if not all(column_names):
# some column names are empty, use pandas reader to take the names from it
pandas_kw["nrows"] = 1
df = pandas.read_excel(io, **pandas_kw)
column_names = df.columns

# Compute partition metadata upfront so it is uniform for all partitions
chunk_size = max(1, (total_bytes - f.tell()) // num_partitions)
num_splits = min(len(column_names), num_partitions)
Expand Down
Binary file added modin/pandas/test/data/test_emptyline.xlsx
Binary file not shown.
7 changes: 7 additions & 0 deletions modin/pandas/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,13 @@ def test_from_excel_sheetname_title():
df_equals(modin_df, pandas_df)


@check_file_leaks
def test_excel_empty_line():
path = "modin/pandas/test/data/test_emptyline.xlsx"
modin_df = pd.read_excel(path)
assert str(modin_df)


@pytest.mark.parametrize(
"sheet_name",
["Sheet1", "AnotherSpecialName", "SpecialName", "SecondSpecialName", 0, 1, 2, 3],
Expand Down