-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Changes from 1 commit
23a0cec
5a59cd0
4171dd6
91438b8
4c6da13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
Strings are used for sheet names, Integers are used in zero-indexed | ||
sheet positions. | ||
|
@@ -144,7 +144,7 @@ | |
Returns | ||
------- | ||
parsed : DataFrame or Dict of DataFrames | ||
DataFrame from the passed in Excel file. See notes in sheetname | ||
DataFrame from the passed in Excel file. See notes in sheet_name | ||
argument for more information on when a Dict of Dataframes is returned. | ||
""" | ||
|
||
|
@@ -190,7 +190,7 @@ def get_writer(engine_name): | |
|
||
|
||
@Appender(_read_excel_doc) | ||
def read_excel(io, sheetname=0, header=0, skiprows=None, skip_footer=0, | ||
def read_excel(io, sheet_name=0, header=0, skiprows=None, skip_footer=0, | ||
index_col=None, names=None, parse_cols=None, parse_dates=False, | ||
date_parser=None, na_values=None, thousands=None, | ||
convert_float=True, has_index_names=None, converters=None, | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. you can use |
||
|
||
return io._parse_excel( | ||
sheetname=sheetname, header=header, skiprows=skiprows, names=names, | ||
sheetname=sheet_name, header=header, skiprows=skiprows, names=names, | ||
index_col=index_col, parse_cols=parse_cols, parse_dates=parse_dates, | ||
date_parser=date_parser, na_values=na_values, thousands=thousands, | ||
convert_float=convert_float, has_index_names=has_index_names, | ||
|
@@ -266,7 +270,7 @@ def __init__(self, io, **kwds): | |
def __fspath__(self): | ||
return self._io | ||
|
||
def parse(self, sheetname=0, header=0, skiprows=None, skip_footer=0, | ||
def parse(self, sheet_name=0, header=0, skiprows=None, skip_footer=0, | ||
names=None, index_col=None, parse_cols=None, parse_dates=False, | ||
date_parser=None, na_values=None, thousands=None, | ||
convert_float=True, has_index_names=None, | ||
|
@@ -279,7 +283,7 @@ def parse(self, sheetname=0, header=0, skiprows=None, skip_footer=0, | |
docstring for more info on accepted parameters | ||
""" | ||
|
||
return self._parse_excel(sheetname=sheetname, header=header, | ||
return self._parse_excel(sheetname=sheet_name, header=header, | ||
skiprows=skiprows, names=names, | ||
index_col=index_col, | ||
has_index_names=has_index_names, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. comments go inside the function. |
||
# GH10969: DOC: Consistent variable names (sheetname vs sheet_name, issue 10559) | ||
# GH12604: CLN GH10559 Rename sheetname variable to sheet_name for consistency | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. You can assert that a warning is issued with the |
||
|
||
tm.assert_frame_equal(df1, dfref, check_names=False) | ||
tm.assert_frame_equal(df2, dfref, check_names=False) | ||
|
||
|
||
|
||
class XlrdTests(ReadingTestsBase): | ||
""" | ||
|
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 wellThere 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