From add59ae25398c6aa18ff3c8b158896890b7b1fa0 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 19 May 2019 19:49:53 -0700 Subject: [PATCH 1/7] CLN: Remove ExcelWriter.sheetname --- pandas/io/excel/_base.py | 16 ---------------- pandas/tests/io/test_excel.py | 25 +++++-------------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index c0678575fd6f0..6ced5fa6a33ee 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -291,12 +291,6 @@ def read_excel(io, mangle_dupe_cols=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`") @@ -833,16 +827,6 @@ def parse(self, DataFrame or dict of DataFrames DataFrame from the passed in Excel file. """ - - # 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") - elif 'sheetname' in kwds: - raise TypeError("Cannot specify both `sheet_name` " - "and `sheetname`. Use just `sheet_name`") - if 'chunksize' in kwds: raise NotImplementedError("chunksize keyword of read_excel " "is not implemented") diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 112d14795d9bf..0cdd38cabec2d 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -346,9 +346,6 @@ 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') @@ -656,32 +653,20 @@ def test_sheet_name_and_sheetname(self, ext): df_ref = self.get_csv_refdf(filename) df1 = self.get_exceldf(filename, ext, sheet_name=sheet_name, index_col=0) # doc - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - with ignore_xlrd_time_clock_warning(): - df2 = self.get_exceldf(filename, ext, index_col=0, - sheetname=sheet_name) # backward compat + with ignore_xlrd_time_clock_warning(): + df2 = self.get_exceldf(filename, ext, index_col=0, + sheet_name=sheet_name) excel = self.get_excelfile(filename, ext) df1_parse = excel.parse(sheet_name=sheet_name, index_col=0) # doc - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - df2_parse = excel.parse(index_col=0, - sheetname=sheet_name) # backward compat + df2_parse = excel.parse(index_col=0, + sheet_name=sheet_name) tm.assert_frame_equal(df1, df_ref, check_names=False) tm.assert_frame_equal(df2, df_ref, check_names=False) tm.assert_frame_equal(df1_parse, df_ref, check_names=False) tm.assert_frame_equal(df2_parse, df_ref, check_names=False) - def test_sheet_name_both_raises(self, ext): - with pytest.raises(TypeError, match="Cannot specify both"): - self.get_exceldf('test1', ext, sheetname='Sheet1', - sheet_name='Sheet1') - - excel = self.get_excelfile('test1', ext) - with pytest.raises(TypeError, match="Cannot specify both"): - excel.parse(sheetname='Sheet1', - sheet_name='Sheet1') - def test_excel_read_buffer(self, ext): pth = os.path.join(self.dirpath, 'test1' + ext) From 8c9bfbaa8bdc197041f7d4508fadf4fd932b8abf Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 19 May 2019 19:53:56 -0700 Subject: [PATCH 2/7] Add whatsnew --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 84f9fd8906dbf..ddaf777eee723 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -268,7 +268,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Removed ``Panel`` (:issue:`25047`, :issue:`25191`, :issue:`25231`) -- +- Removed the previously deprecated `ExcelWriter.sheetname` (:issue:`16442`, :issue:`20938`) - - From 569a6499898ff900d7383f3c78cb01f0c0556547 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 19 May 2019 19:57:21 -0700 Subject: [PATCH 3/7] Double backtick --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index ddaf777eee723..18dad7ecf830d 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -268,7 +268,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Removed ``Panel`` (:issue:`25047`, :issue:`25191`, :issue:`25231`) -- Removed the previously deprecated `ExcelWriter.sheetname` (:issue:`16442`, :issue:`20938`) +- Removed the previously deprecated ``ExcelWriter.sheetname`` (:issue:`16442`, :issue:`20938`) - - From 73c5e9d887cd0874767d9a31cd5abb088a5df8b3 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 20 May 2019 09:22:24 -0700 Subject: [PATCH 4/7] Remove usused import --- pandas/io/excel/_base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 6ced5fa6a33ee..7e974a6b78b08 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -5,7 +5,6 @@ import os from textwrap import fill from urllib.request import urlopen -import warnings from pandas._config import config From c7918fbea0a93951916157bf1bd6b2f622bc4b7c Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 20 May 2019 09:52:30 -0700 Subject: [PATCH 5/7] Test sheetname raised TypeError --- pandas/io/excel/_base.py | 7 ++++--- pandas/tests/io/test_excel.py | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 7e974a6b78b08..a0d51e85aa4f3 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -290,9 +290,10 @@ def read_excel(io, mangle_dupe_cols=True, **kwds): - if 'sheet' in kwds: - raise TypeError("read_excel() got an unexpected keyword argument " - "`sheet`") + for arg in ('sheet', 'sheetname'): + if arg in kwds: + raise TypeError("read_excel() got an unexpected keyword argument " + "`{}`".format(arg)) if not isinstance(io, ExcelFile): io = ExcelFile(io, engine=engine) diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 0cdd38cabec2d..cf639bd2b4e3d 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -342,12 +342,15 @@ def test_excel_passes_na(self, ext): tm.assert_frame_equal(parsed, expected) @td.skip_if_no('xlrd', '1.0.1') # GH-22682 - def test_deprecated_sheetname(self, ext): + @pytest.mark.parametrize('arg', ['sheet', 'sheetname']) + def test_deprecated_sheetname(self, ext, arg): # gh-17964 excel = self.get_excelfile('test1', ext) - with pytest.raises(TypeError): - read_excel(excel, sheet='Sheet1') + kwarg = {arg: 'Sheet1'} + msg = "unexpected keyword argument `{}`".format(arg) + with pytest.raises(TypeError, match=msg): + read_excel(excel, **kwarg) @td.skip_if_no('xlrd', '1.0.1') # GH-22682 def test_excel_table_sheet_by_index(self, ext): From 47478da86064c443e263599f8b561e3a2de57403 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 20 May 2019 11:31:22 -0700 Subject: [PATCH 6/7] Change whatsnew --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index a4d579aa7488f..32e70217f0761 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -269,7 +269,7 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Removed ``Panel`` (:issue:`25047`, :issue:`25191`, :issue:`25231`) -- Removed the previously deprecated ``ExcelWriter.sheetname`` (:issue:`16442`, :issue:`20938`) +- Removed the previously deprecated ``sheetname`` keyword in :func:`read_excel` (:issue:`16442`, :issue:`20938`) - - From b98aab11bf793182c751053866fc408e5787ad2d Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Fri, 24 May 2019 14:15:41 -0700 Subject: [PATCH 7/7] Change test name --- pandas/tests/io/test_excel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 9924c41594bbe..44ce3111c3a1e 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -343,7 +343,7 @@ def test_excel_passes_na(self, ext): @td.skip_if_no('xlrd', '1.0.1') # GH-22682 @pytest.mark.parametrize('arg', ['sheet', 'sheetname']) - def test_deprecated_sheetname(self, ext, arg): + def test_unexpected_kwargs_raises(self, ext, arg): # gh-17964 excel = self.get_excelfile('test1', ext)