Skip to content

Commit def7a73

Browse files
lucianoviolajreback
authored andcommitted
ENH: Raise error for 'sheet' arg in read_excel (#18604)
* ENH: Raise error for read_excel possible "sheet" argument in kwargs (#17994)
1 parent a82d779 commit def7a73

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ I/O
377377
^^^
378378

379379
- :func:`read_html()` no longer ignores all-whitespace ``<tr>`` within ``<thead>`` when considering the ``skiprows`` and ``header`` arguments. Previously, users had to decrease their ``header`` and ``skiprows`` values on such tables to work around the issue. (:issue:`21641`)
380-
-
380+
- :func:`read_excel()` will correctly show the deprecation warning for previously deprecated ``sheetname`` (:issue:`17994`)
381381
-
382382

383383
Plotting

pandas/io/excel.py

+10
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,16 @@ def read_excel(io,
303303
convert_float=True,
304304
**kwds):
305305

306+
# Can't use _deprecate_kwarg since sheetname=None has a special meaning
307+
if is_integer(sheet_name) and sheet_name == 0 and 'sheetname' in kwds:
308+
warnings.warn("The `sheetname` keyword is deprecated, use "
309+
"`sheet_name` instead", FutureWarning, stacklevel=2)
310+
sheet_name = kwds.pop("sheetname")
311+
312+
if 'sheet' in kwds:
313+
raise TypeError("read_excel() got an unexpected keyword argument "
314+
"`sheet`")
315+
306316
if not isinstance(io, ExcelFile):
307317
io = ExcelFile(io, engine=engine)
308318

pandas/tests/io/test_excel.py

+10
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ def test_excel_passes_na(self, ext):
219219
columns=['Test'])
220220
tm.assert_frame_equal(parsed, expected)
221221

222+
def test_deprecated_sheetname(self, ext):
223+
# gh-17964
224+
excel = self.get_excelfile('test1', ext)
225+
226+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
227+
read_excel(excel, sheetname='Sheet1')
228+
229+
with pytest.raises(TypeError):
230+
read_excel(excel, sheet='Sheet1')
231+
222232
def test_excel_table_sheet_by_index(self, ext):
223233

224234
excel = self.get_excelfile('test1', ext)

0 commit comments

Comments
 (0)