Skip to content

ENH: Pandas Series provide to_excel method #14780

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

Merged
merged 3 commits into from
Dec 5, 2016

Conversation

s-celles
Copy link
Contributor

@s-celles s-celles commented Dec 1, 2016

strings before writing.
"""
from pandas.core.frame import DataFrame
df = DataFrame(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use .to_frame.

"""
from pandas.core.frame import DataFrame
df = DataFrame(self)
df.to_excel(excel_writer, sheet_name, na_rep,
Copy link
Member

@sinhrks sinhrks Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls use keyword args as locations may be changed.

@sinhrks sinhrks added API Design IO Excel read_excel, to_excel labels Dec 1, 2016
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use shared docs here to avoid repeating everything

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show me an example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look for shared_doc

Copy link
Contributor Author

@s-celles s-celles Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this shared docstring be in pandas/io/excel.py or somewhere else?

@@ -2619,6 +2619,19 @@ def to_csv(self, path=None, index=True, sep=",", na_rep='',
if path is None:
return result

@Appender(generic._shared_docs['to_excel'] % _shared_doc_kwargs)
def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add to the doc-string a versionadded tag (0.20.)

@jreback
Copy link
Contributor

jreback commented Dec 1, 2016

this prob needs to be added to api.rst as well

@s-celles
Copy link
Contributor Author

s-celles commented Dec 2, 2016

Could you retrigger this job ? Thanks

@sinhrks
Copy link
Member

sinhrks commented Dec 2, 2016

@scls19fr The job fails because of a lint error. pls fix.

@codecov-io
Copy link

codecov-io commented Dec 2, 2016

Current coverage is 85.27% (diff: 100%)

Merging #14780 into master will increase coverage by <.01%

@@             master     #14780   diff @@
==========================================
  Files           144        144          
  Lines         50946      50953     +7   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43445      43452     +7   
  Misses         7501       7501          
  Partials          0          0          

Powered by Codecov. Last update c0e13d1...0ab4876

@s-celles
Copy link
Contributor Author

s-celles commented Dec 2, 2016

Thanks @sinhrks I didn't noticed because that's only for 1 job.

_shared_docs['to_excel'] = """
Write %(klass)s to a excel sheet

.. versionadded:: 0.20.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the case for DataFrame. You can add it separately for series with _shared_doc_kwargs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorisvandenbossche how will you name this key in _shared_doc_kwargs?
What value will you put? .. versionadded:: 0.20.0 or 0.20.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one, as for DataFrame.excel there should be no versionadded

@@ -49,7 +49,7 @@ Other enhancements
^^^^^^^^^^^^^^^^^^

- ``pd.read_excel`` now preserves sheet order when using ``sheetname=None`` (:issue:`9930`)

- ``Series`` provides a ``to_excel`` method to output Excel files (:issue:`8825`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Series has gained a .to_excel method, to output Excel files, similar to DataFrame.to_excel

@@ -105,7 +105,8 @@
axes_single_arg="{0 or 'index', 1 or 'columns'}",
optional_by="""
by : str or list of str
Name or list of names which refer to the axis items.""")
Name or list of names which refer to the axis items.""",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorisvandenbossche any better way to do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine (given our current way of doing this with _shared_doc_kwargs. This could maybe get an overhaul, but that is another issue :-))

@jreback
Copy link
Contributor

jreback commented Dec 4, 2016

pls rebase and push again

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, small comment regarding newlines in the resulting docstring

Write %(klass)s to a excel sheet

%(versionadded_to_excel)s

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the blank lines before and after the versionadded here? And include the newlines in the versionadded_to_excel arg for Series. Because otherwise for DataFrame.to_excel, you would get three blank lines instead of one here.

@@ -105,7 +105,8 @@
axes_single_arg="{0 or 'index', 1 or 'columns'}",
optional_by="""
by : str or list of str
Name or list of names which refer to the axis items.""")
Name or list of names which refer to the axis items.""",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine (given our current way of doing this with _shared_doc_kwargs. This could maybe get an overhaul, but that is another issue :-))

@jorisvandenbossche jorisvandenbossche added this to the 0.20.0 milestone Dec 5, 2016
@jorisvandenbossche jorisvandenbossche merged commit b3dd9ba into pandas-dev:master Dec 5, 2016
@jorisvandenbossche
Copy link
Member

@scls19fr Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pandas Series should provide to_excel method
5 participants