Skip to content

Commit

Permalink
CLN: Move to_excel to generic.py (pandas-dev#23656)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung authored and Alex Volkov committed Nov 13, 2018
1 parent 151c22a commit 4134d4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
18 changes: 0 additions & 18 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,24 +1829,6 @@ def to_panel(self):

return self._constructor_expanddim(new_mgr)

@Appender(_shared_docs['to_excel'] % _shared_doc_kwargs)
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
float_format=None, columns=None, header=True, index=True,
index_label=None, startrow=0, startcol=0, engine=None,
merge_cells=True, encoding=None, inf_rep='inf', verbose=True,
freeze_panes=None):

from pandas.io.formats.excel import ExcelFormatter
formatter = ExcelFormatter(self, na_rep=na_rep, cols=columns,
header=header,
float_format=float_format, index=index,
index_label=index_label,
merge_cells=merge_cells,
inf_rep=inf_rep)
formatter.write(excel_writer, sheet_name=sheet_name, startrow=startrow,
startcol=startcol, freeze_panes=freeze_panes,
engine=engine)

@deprecate_kwarg(old_arg_name='encoding', new_arg_name=None)
def to_stata(self, fname, convert_dates=None, write_index=True,
encoding="latin-1", byteorder=None, time_stamp=None,
Expand Down
34 changes: 27 additions & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,16 +1977,17 @@ def _repr_latex_(self):
# I/O Methods

_shared_docs['to_excel'] = """
Write %(klass)s to an excel sheet.
Write %(klass)s to an Excel sheet.
To write a single %(klass)s to an excel .xlsx file it is only necessary to
To write a single %(klass)s to an Excel .xlsx file it is only necessary to
specify a target file name. To write to multiple sheets it is necessary to
create an `ExcelWriter` object with a target file name, and specify a sheet
in the file to write to. Multiple sheets may be written to by
specifying unique `sheet_name`. With all data written to the file it is
necessary to save the changes. Note that creating an ExcelWriter object
with a file name that already exists will result in the contents of the
existing file being erased.
in the file to write to.
Multiple sheets may be written to by specifying unique `sheet_name`.
With all data written to the file it is necessary to save the changes.
Note that creating an `ExcelWriter` object with a file name that already
exists will result in the contents of the existing file being erased.
Parameters
----------
Expand Down Expand Up @@ -9951,6 +9952,25 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
if path_or_buf is None:
return formatter.path_or_buf.getvalue()

@Appender(_shared_docs["to_excel"] % dict(klass="object"))
def to_excel(self, excel_writer, sheet_name="Sheet1", na_rep="",
float_format=None, columns=None, header=True, index=True,
index_label=None, startrow=0, startcol=0, engine=None,
merge_cells=True, encoding=None, inf_rep="inf", verbose=True,
freeze_panes=None):
df = self if isinstance(self, ABCDataFrame) else self.to_frame()

from pandas.io.formats.excel import ExcelFormatter
formatter = ExcelFormatter(df, na_rep=na_rep, cols=columns,
header=header,
float_format=float_format, index=index,
index_label=index_label,
merge_cells=merge_cells,
inf_rep=inf_rep)
formatter.write(excel_writer, sheet_name=sheet_name, startrow=startrow,
startcol=startcol, freeze_panes=freeze_panes,
engine=engine)


def _doc_parms(cls):
"""Return a tuple of the doc parms."""
Expand Down
13 changes: 0 additions & 13 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3970,19 +3970,6 @@ def to_csv(self, *args, **kwargs):
kwargs["header"] = False # Backwards compatibility.
return self.to_frame().to_csv(**kwargs)

@Appender(generic._shared_docs['to_excel'] % _shared_doc_kwargs)
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
float_format=None, columns=None, header=True, index=True,
index_label=None, startrow=0, startcol=0, engine=None,
merge_cells=True, encoding=None, inf_rep='inf', verbose=True):
df = self.to_frame()
df.to_excel(excel_writer=excel_writer, sheet_name=sheet_name,
na_rep=na_rep, float_format=float_format, columns=columns,
header=header, index=index, index_label=index_label,
startrow=startrow, startcol=startcol, engine=engine,
merge_cells=merge_cells, encoding=encoding,
inf_rep=inf_rep, verbose=verbose)

@Appender(generic._shared_docs['isna'] % _shared_doc_kwargs)
def isna(self):
return super(Series, self).isna()
Expand Down

0 comments on commit 4134d4a

Please sign in to comment.