Skip to content

Commit de449aa

Browse files
Avassegdementen
authored andcommitted
fix(#580): Renamed sheetname to sheet in to_excel
1 parent 2f5b0d3 commit de449aa

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎doc/source/changes/version_0_28.rst.inc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ Miscellaneous improvements
318318

319319
* renamed argument `sheetname` of `read_excel` function as `sheet` (closes :issue:`587`).
320320

321+
* Renamed sheet_name of LArray.to_excel to sheet since it can also be an index (closes :issue:580).
321322

322323
Fixes
323324
-----

‎larray/core/array.py‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5979,7 +5979,8 @@ def to_hdf(self, filepath, key, *args, **kwargs):
59795979
key = _translate_key_hdf(key)
59805980
self.to_frame().to_hdf(filepath, key, *args, **kwargs)
59815981

5982-
def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file=False, clear_sheet=False,
5982+
@deprecate_kwarg('sheet_name', 'sheet')
5983+
def to_excel(self, filepath=None, sheet=None, position='A1', overwrite_file=False, clear_sheet=False,
59835984
header=True, transpose=False, wide=True, value_name='value', engine=None, *args, **kwargs):
59845985
"""
59855986
Writes array in the specified sheet of specified excel workbook.
@@ -5990,9 +5991,9 @@ def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file
59905991
Path where the excel file has to be written. If None (default), creates a new Excel Workbook in a live Excel
59915992
instance (Windows only). Use -1 to use the currently active Excel Workbook. Use a name without extension
59925993
(.xlsx) to use any unsaved* workbook.
5993-
sheet_name : str or Group or int or None, optional
5994+
sheet : str or Group or int or None, optional
59945995
Sheet where the data has to be written. Defaults to None, Excel standard name if adding a sheet to an
5995-
existing file, "Sheet1" otherwise. sheet_name can also refer to the position of the sheet
5996+
existing file, "Sheet1" otherwise. sheet can also refer to the position of the sheet
59965997
(e.g. 0 for the first sheet, -1 for the last one).
59975998
position : str or tuple of integers, optional
59985999
Integer position (row, column) must be 1-based. Defaults to 'A1'.
@@ -6028,7 +6029,7 @@ def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file
60286029
>>> # add to existing sheet starting at position A15
60296030
>>> a.to_excel('test.xlsx', 'Sheet1', 'A15') # doctest: +SKIP
60306031
"""
6031-
sheet_name = _translate_sheet_name(sheet_name)
6032+
sheet = _translate_sheet_name(sheet)
60326033

60336034
if wide:
60346035
pd_obj = self.to_frame(fold_last_axis_name=True)
@@ -6057,29 +6058,29 @@ def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file
60576058
wb = open_excel(filepath, overwrite_file=overwrite_file)
60586059

60596060
if new_workbook:
6060-
sheet = wb.sheets[0]
6061-
if sheet_name is not None:
6062-
sheet.name = sheet_name
6063-
elif sheet_name is not None and sheet_name in wb:
6064-
sheet = wb.sheets[sheet_name]
6061+
sheetobj = wb.sheets[0]
6062+
if sheet is not None:
6063+
sheetobj.name = sheet
6064+
elif sheet is not None and sheet in wb:
6065+
sheetobj = wb.sheets[sheet]
60656066
if clear_sheet:
6066-
sheet.clear()
6067+
sheetobj.clear()
60676068
else:
6068-
sheet = wb.sheets.add(sheet_name, after=wb.sheets[-1])
6069+
sheetobj = wb.sheets.add(sheet, after=wb.sheets[-1])
60696070

60706071
options = dict(header=header, index=header, transpose=transpose)
6071-
sheet[position].options(**options).value = pd_obj
6072+
sheetobj[position].options(**options).value = pd_obj
60726073
# TODO: implement wide via/in dump
60736074
# sheet[position] = self.dump(header=header, wide=wide)
60746075
if close:
60756076
wb.save()
60766077
wb.close()
60776078
else:
6078-
if sheet_name is None:
6079-
sheet_name = 'Sheet1'
6079+
if sheet is None:
6080+
sheet = 'Sheet1'
60806081
# TODO: implement position in this case
60816082
# startrow, startcol
6082-
pd_obj.to_excel(filepath, sheet_name, *args, engine=engine, **kwargs)
6083+
pd_obj.to_excel(filepath, sheet, *args, engine=engine, **kwargs)
60836084

60846085
def to_clipboard(self, *args, **kwargs):
60856086
"""Sends the content of the array to clipboard.

0 commit comments

Comments
 (0)