Skip to content

Commit

Permalink
ENH: Raise error for 'sheet' arg in read_excel (#18604)
Browse files Browse the repository at this point in the history
* ENH: Raise error for read_excel possible "sheet" argument in kwargs (#17994)
  • Loading branch information
lucianoviola authored and jreback committed Jul 7, 2018
1 parent a82d779 commit def7a73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ I/O
^^^

- :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`)
-
- :func:`read_excel()` will correctly show the deprecation warning for previously deprecated ``sheetname`` (:issue:`17994`)
-

Plotting
Expand Down
10 changes: 10 additions & 0 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ def read_excel(io,
convert_float=True,
**kwds):

# Can't use _deprecate_kwarg since sheetname=None has a special meaning
if is_integer(sheet_name) and sheet_name == 0 and 'sheetname' in kwds:
warnings.warn("The `sheetname` keyword is deprecated, use "
"`sheet_name` instead", FutureWarning, stacklevel=2)
sheet_name = kwds.pop("sheetname")

if 'sheet' in kwds:
raise TypeError("read_excel() got an unexpected keyword argument "
"`sheet`")

if not isinstance(io, ExcelFile):
io = ExcelFile(io, engine=engine)

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/io/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ def test_excel_passes_na(self, ext):
columns=['Test'])
tm.assert_frame_equal(parsed, expected)

def test_deprecated_sheetname(self, ext):
# gh-17964
excel = self.get_excelfile('test1', ext)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
read_excel(excel, sheetname='Sheet1')

with pytest.raises(TypeError):
read_excel(excel, sheet='Sheet1')

def test_excel_table_sheet_by_index(self, ext):

excel = self.get_excelfile('test1', ext)
Expand Down

0 comments on commit def7a73

Please sign in to comment.