-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH10559: Minor improvement: Change read_excel sheet name #16442
Conversation
modify io/excel.py and relevant docs (io.rst) to use sheet_name for read_excel but allow sheetname to still be used for backwards compatibility. add test_excel to verify that sheet_name and sheetname args produce the same result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add a note in deprecation section
pandas/io/excel.py
Outdated
@@ -200,8 +200,12 @@ def read_excel(io, sheetname=0, header=0, skiprows=None, skip_footer=0, | |||
if not isinstance(io, ExcelFile): | |||
io = ExcelFile(io, engine=engine) | |||
|
|||
# maintain backwards compatibility by converting sheetname to sheet_name | |||
if 'sheetname' in kwds: | |||
sheet_name = kwds.pop('sheetname') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a deprecation warning on the original arg. You need to also accept the original arg as a kwarg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use pandas.util._decorators.deprecate_kwarg
pandas/tests/io/test_excel.py
Outdated
@@ -544,6 +544,18 @@ def test_date_conversion_overflow(self): | |||
result = self.get_exceldf('testdateoverflow') | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
# GH10559: Minor improvement: Change to_excel "sheet_name" to "sheetname" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments go inside the function.
pandas/tests/io/test_excel.py
Outdated
def test_sheet_name_and_sheetname(self): | ||
dfref = self.get_csv_refdf('test1') | ||
df1 = self.get_exceldf('test1', sheet_name='Sheet1') # doc | ||
df2 = self.get_exceldf('test1', sheetname='Sheet2') # bkwrds compat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should show a FutureWarning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can assert that a warning is issued with thetm.assert_produces_warning
context manager.
added @deprecate_kwarg to read_excel as arg changes from sheetname to sheet_name. moved test comments into function, add assert_produces_warning.
Codecov Report
@@ Coverage Diff @@
## master #16442 +/- ##
==========================================
- Coverage 90.42% 90.42% -0.01%
==========================================
Files 161 161
Lines 51023 51025 +2
==========================================
Hits 46138 46138
- Misses 4885 4887 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16442 +/- ##
==========================================
- Coverage 90.42% 88.26% -2.17%
==========================================
Files 161 161
Lines 51023 51025 +2
==========================================
- Hits 46138 45037 -1101
- Misses 4885 5988 +1103
Continue to review full report at Codecov.
|
remove manual arg change, use @deprecate_kwarg to read_excel as arg changes from sheetname to sheet_name.
shorten lines under 79 char.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add a note in whatsnew (0.21.0) / Deprecations
@@ -48,7 +48,7 @@ | |||
The string could be a URL. Valid URL schemes include http, ftp, s3, | |||
and file. For file URLs, a host is expected. For instance, a local | |||
file could be file://localhost/path/to/workbook.xlsx | |||
sheetname : string, int, mixed list of strings/ints, or None, default 0 | |||
sheet_name : string, int, mixed list of strings/ints, or None, default 0 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add sheetname (DEPRECATED)
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also the deprecated
sphinx directive. I don't see any uses of that, but we can give it a shot here. I think it'd be like
sheetname : string, int, mixed list of strings/ints, or None, default 0
.. deprecated:: 0.21.0
Use `sheet_name` instead
sheet_name : string, int, mixed list of strings/ints, or None, default 0
update whats new 0.21.0 Deprecations section noting sheetname deprecated in favor of sheet_name. add sheetname deprecation in read_excel() docstring.
@abarber4gh thanks, nice job! If you want to check the docs http://pandas-docs.github.io/pandas-docs-travis/generated/pandas.read_excel.html when this build finishes, I'm curious to see how the |
* GH10559: Minor improvement: Change to_excel sheet name modify io/excel.py and relevant docs (io.rst) to use sheet_name for read_excel but allow sheetname to still be used for backwards compatibility. add test_excel to verify that sheet_name and sheetname args produce the same result. * GH10559: Minor improvement: Change to_excel sheet name added @deprecate_kwarg to read_excel as arg changes from sheetname to sheet_name. moved test comments into function, add assert_produces_warning. * GH10559: Minor improvement: Change to_excel sheet name remove manual arg change, use @deprecate_kwarg to read_excel as arg changes from sheetname to sheet_name. * GH10559: Minor improvement: Change to_excel sheet name shorten lines under 79 char. * GH10559: Minor improvement: Change to_excel sheet name update whats new 0.21.0 Deprecations section noting sheetname deprecated in favor of sheet_name. add sheetname deprecation in read_excel() docstring.
modify io/excel.py and relevant docs (io.rst) to use sheet_name for read_excel
but allow sheetname to still be used for backwards compatibility. add test_excel
to verify that sheet_name and sheetname args produce the same result.
git diff upstream/master --name-only -- '*.py' | flake8 --diff