Skip to content

Commit 8c8a175

Browse files
mroeschkeanother-green
authored andcommitted
CLN: Remove ExcelWriter.sheetname (pandas-dev#26464)
xref pandas-devgh-6581
1 parent 9151211 commit 8c8a175

File tree

3 files changed

+16
-44
lines changed

3 files changed

+16
-44
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Deprecations
312312
Removal of prior version deprecations/changes
313313
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
314314
- Removed ``Panel`` (:issue:`25047`, :issue:`25191`, :issue:`25231`)
315-
-
315+
- Removed the previously deprecated ``sheetname`` keyword in :func:`read_excel` (:issue:`16442`, :issue:`20938`)
316316
- Removed previously deprecated ``TimeGrouper`` (:issue:`16942`)
317317
-
318318

pandas/io/excel/_base.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
from textwrap import fill
77
from urllib.request import urlopen
8-
import warnings
98

109
from pandas._config import config
1110

@@ -291,15 +290,10 @@ def read_excel(io,
291290
mangle_dupe_cols=True,
292291
**kwds):
293292

294-
# Can't use _deprecate_kwarg since sheetname=None has a special meaning
295-
if is_integer(sheet_name) and sheet_name == 0 and 'sheetname' in kwds:
296-
warnings.warn("The `sheetname` keyword is deprecated, use "
297-
"`sheet_name` instead", FutureWarning, stacklevel=2)
298-
sheet_name = kwds.pop("sheetname")
299-
300-
if 'sheet' in kwds:
301-
raise TypeError("read_excel() got an unexpected keyword argument "
302-
"`sheet`")
293+
for arg in ('sheet', 'sheetname'):
294+
if arg in kwds:
295+
raise TypeError("read_excel() got an unexpected keyword argument "
296+
"`{}`".format(arg))
303297

304298
if not isinstance(io, ExcelFile):
305299
io = ExcelFile(io, engine=engine)
@@ -833,16 +827,6 @@ def parse(self,
833827
DataFrame or dict of DataFrames
834828
DataFrame from the passed in Excel file.
835829
"""
836-
837-
# Can't use _deprecate_kwarg since sheetname=None has a special meaning
838-
if is_integer(sheet_name) and sheet_name == 0 and 'sheetname' in kwds:
839-
warnings.warn("The `sheetname` keyword is deprecated, use "
840-
"`sheet_name` instead", FutureWarning, stacklevel=2)
841-
sheet_name = kwds.pop("sheetname")
842-
elif 'sheetname' in kwds:
843-
raise TypeError("Cannot specify both `sheet_name` "
844-
"and `sheetname`. Use just `sheet_name`")
845-
846830
if 'chunksize' in kwds:
847831
raise NotImplementedError("chunksize keyword of read_excel "
848832
"is not implemented")

pandas/tests/io/test_excel.py

+11-23
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ def test_excel_passes_na(self, ext):
342342
tm.assert_frame_equal(parsed, expected)
343343

344344
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
345-
def test_deprecated_sheetname(self, ext):
345+
@pytest.mark.parametrize('arg', ['sheet', 'sheetname'])
346+
def test_unexpected_kwargs_raises(self, ext, arg):
346347
# gh-17964
347348
excel = self.get_excelfile('test1', ext)
348349

349-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
350-
read_excel(excel, sheetname='Sheet1')
351-
352-
with pytest.raises(TypeError):
353-
read_excel(excel, sheet='Sheet1')
350+
kwarg = {arg: 'Sheet1'}
351+
msg = "unexpected keyword argument `{}`".format(arg)
352+
with pytest.raises(TypeError, match=msg):
353+
read_excel(excel, **kwarg)
354354

355355
@td.skip_if_no('xlrd', '1.0.1') # GH-22682
356356
def test_excel_table_sheet_by_index(self, ext):
@@ -588,32 +588,20 @@ def test_sheet_name_and_sheetname(self, ext):
588588
df_ref = self.get_csv_refdf(filename)
589589
df1 = self.get_exceldf(filename, ext,
590590
sheet_name=sheet_name, index_col=0) # doc
591-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
592-
with ignore_xlrd_time_clock_warning():
593-
df2 = self.get_exceldf(filename, ext, index_col=0,
594-
sheetname=sheet_name) # backward compat
591+
with ignore_xlrd_time_clock_warning():
592+
df2 = self.get_exceldf(filename, ext, index_col=0,
593+
sheet_name=sheet_name)
595594

596595
excel = self.get_excelfile(filename, ext)
597596
df1_parse = excel.parse(sheet_name=sheet_name, index_col=0) # doc
598-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
599-
df2_parse = excel.parse(index_col=0,
600-
sheetname=sheet_name) # backward compat
597+
df2_parse = excel.parse(index_col=0,
598+
sheet_name=sheet_name)
601599

602600
tm.assert_frame_equal(df1, df_ref, check_names=False)
603601
tm.assert_frame_equal(df2, df_ref, check_names=False)
604602
tm.assert_frame_equal(df1_parse, df_ref, check_names=False)
605603
tm.assert_frame_equal(df2_parse, df_ref, check_names=False)
606604

607-
def test_sheet_name_both_raises(self, ext):
608-
with pytest.raises(TypeError, match="Cannot specify both"):
609-
self.get_exceldf('test1', ext, sheetname='Sheet1',
610-
sheet_name='Sheet1')
611-
612-
excel = self.get_excelfile('test1', ext)
613-
with pytest.raises(TypeError, match="Cannot specify both"):
614-
excel.parse(sheetname='Sheet1',
615-
sheet_name='Sheet1')
616-
617605
def test_excel_read_buffer(self, ext):
618606

619607
pth = os.path.join(self.dirpath, 'test1' + ext)

0 commit comments

Comments
 (0)