Skip to content

Commit 77c956d

Browse files
JasperVanDenBoschNico Cernek
authored and
Nico Cernek
committed
BUG: fixes formatted value error for missing sheet (pandas-dev#27676) (pandas-dev#27677)
1 parent 812989e commit 77c956d

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ I/O
409409
- Bug in :func:`read_hdf` closing stores that it didn't open when Exceptions are raised (:issue:`28699`)
410410
- Bug in :meth:`DataFrame.read_json` where using ``orient="index"`` would not maintain the order (:issue:`28557`)
411411
- Bug in :meth:`DataFrame.to_html` where the length of the ``formatters`` argument was not verified (:issue:`28469`)
412+
- Bug in :meth:`DataFrame.read_excel` with ``engine='ods'`` when ``sheet_name`` argument references a non-existent sheet (:issue:`27676`)
412413
- Bug in :meth:`pandas.io.formats.style.Styler` formatting for floating values not displaying decimals correctly (:issue:`13257`)
413414
- Bug in :meth:`DataFrame.to_html` when using ``formatters=<list>`` and ``max_cols`` together. (:issue:`25955`)
414415

pandas/io/excel/_odfreader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def get_sheet_by_name(self, name: str):
6161
if table.getAttribute("name") == name:
6262
return table
6363

64-
raise ValueError("sheet {name} not found".format(name))
64+
raise ValueError("sheet {} not found".format(name))
6565

6666
def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]:
6767
"""Parse an ODF Table into a list of lists

pandas/tests/io/excel/test_odf.py

+8
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ def test_read_writer_table():
3636
result = pd.read_excel("writertable.odt", "Table1", index_col=0)
3737

3838
tm.assert_frame_equal(result, expected)
39+
40+
41+
def test_nonexistent_sheetname_raises(read_ext):
42+
# GH-27676
43+
# Specifying a non-existent sheet_name parameter should throw an error
44+
# with the sheet name.
45+
with pytest.raises(ValueError, match="sheet xyz not found"):
46+
pd.read_excel("blank.ods", sheet_name="xyz")

0 commit comments

Comments
 (0)