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-#2402: Fix read_excel when files come from older windows #2403

Merged
merged 1 commit into from
Nov 25, 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
2 changes: 1 addition & 1 deletion modin/backends/pandas/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def parse(fname, **kwargs):
ws = Worksheet(wb)
# Read the raw data
with ZipFile(fname) as z:
with z.open("xl/worksheets/{}.xml".format(sheet_name.lower())) as file:
with z.open("xl/worksheets/{}.xml".format(sheet_name)) as file:
file.seek(start)
bytes_data = file.read(end - start)

Expand Down
23 changes: 15 additions & 8 deletions modin/engines/base/io/text/excel_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ def _read(cls, io, **kwargs):
ex.read_manifest()
ex.read_strings()
ws = Worksheet(wb)
# Convert index to sheet name in file
if isinstance(sheet_name, int):
sheet_name = "sheet{}".format(sheet_name + 1)
else:
sheet_name = "sheet{}".format(wb.sheetnames.index(sheet_name) + 1)
# Pass this value to the workers
kwargs["sheet_name"] = sheet_name

with ZipFile(io) as z:
from io import BytesIO

f = z.open("xl/worksheets/{}.xml".format(sheet_name.lower()))
# Convert index to sheet name in file
if isinstance(sheet_name, int):
sheet_name = "sheet{}".format(sheet_name + 1)
else:
sheet_name = "sheet{}".format(wb.sheetnames.index(sheet_name) + 1)
if any(sheet_name.lower() in name for name in z.namelist()):
sheet_name = sheet_name.lower()
elif any(sheet_name.title() in name for name in z.namelist()):
sheet_name = sheet_name.title()
else:
raise ValueError("Sheet {} not found".format(sheet_name.lower()))
# Pass this value to the workers
kwargs["sheet_name"] = sheet_name

f = z.open("xl/worksheets/{}.xml".format(sheet_name))
f = BytesIO(f.read())
total_bytes = cls.file_size(f)

Expand Down
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 @@ -888,6 +888,13 @@ def test_from_excel_all_sheets():
teardown_excel_file()


def test_from_excel_sheetname_title():
path = "modin/pandas/test/data/excel_sheetname_title.xlsx"
modin_df = pd.read_excel(path)
pandas_df = pandas.read_excel(path)
df_equals(modin_df, pandas_df)


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