Skip to content

Commit

Permalink
Fix indices when reading Excel files in parallel (#2526)
Browse files Browse the repository at this point in the history
Signed-off-by: Vasilij Litvinov <vasilij.n.litvinov@intel.com>
  • Loading branch information
vnlitvinov authored Dec 9, 2020
1 parent e76366b commit 2592849
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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

0 comments on commit 2592849

Please sign in to comment.