Skip to content

BUG: Ignore chartsheets #41698

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 9 commits into from
Jul 2, 2021
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
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 @@ -985,6 +985,7 @@ I/O
- Bug in the conversion from pyarrow to pandas (e.g. for reading Parquet) with nullable dtypes and a pyarrow array whose data buffer size is not a multiple of dtype size (:issue:`40896`)
- Bug in :func:`read_excel` would raise an error when pandas could not determine the file type, even when user specified the ``engine`` argument (:issue:`41225`)
- Bug in :func:`read_clipboard` copying from an excel file shifts values into the wrong column if there are null values in first column (:issue:`41108`)
- Bug in :func:`read_excel` attempting to read chart sheets from .xlsx files (:issue:`41448`)

Period
^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def close(self):

@property
def sheet_names(self) -> list[str]:
return self.book.sheetnames
return [sheet.title for sheet in self.book.worksheets]

def get_sheet_by_name(self, name: str):
self.raise_if_bad_sheet_by_name(name)
Expand Down
Binary file added pandas/tests/io/data/excel/chartsheet.xls
Binary file not shown.
Binary file added pandas/tests/io/data/excel/chartsheet.xlsb
Binary file not shown.
Binary file added pandas/tests/io/data/excel/chartsheet.xlsm
Binary file not shown.
Binary file added pandas/tests/io/data/excel/chartsheet.xlsx
Binary file not shown.
13 changes: 13 additions & 0 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,3 +1499,16 @@ def test_engine_invalid_option(self, read_ext):
with pytest.raises(ValueError, match="Value must be one of *"):
with pd.option_context(f"io.excel{read_ext}.reader", "abc"):
pass

def test_ignore_chartsheets(self, request, engine, read_ext):
# GH 41448
if engine == "odf":
pytest.skip("chartsheets do not exist in the ODF format")
if engine == "pyxlsb":
request.node.add_marker(
pytest.mark.xfail(
reason="pyxlsb can't distinguish chartsheets from worksheets"
)
)
with pd.ExcelFile("chartsheet" + read_ext) as excel:
assert excel.sheet_names == ["Sheet1"]