-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
DOC: Expose ExcelWriter as part of the Generated API #22359
Conversation
Codecov Report
@@ Coverage Diff @@
## master #22359 +/- ##
=======================================
Coverage 92.05% 92.05%
=======================================
Files 169 169
Lines 50733 50733
=======================================
Hits 46702 46702
Misses 4031 4031
Continue to review full report at Codecov.
|
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.
Thanks for the PR! Can you also add an examples section to the docstring so people know how to use it?
I think we should also prevent the abstract properties and methods from being rendered, but copying @datapythonista for input
@WillAyd yeap i'll try to add an example:) |
Yes, and I would also add a note in the docstring explicitly saying that none of the methods/properties are considered public? (only 'public' usage is what is in the example?)
|
@newinh this is really shaping up! When I built your latest commit locally I was still seeing the methods and attributes we are trying to hide - were you not seeing these on your end? I think there is still something that needs to be tweaked there. One other thing that would make this nice - the |
Looking at how the
|
Can you also add a note in the docstring explicitly saying that none of the methods/properties are considered public? |
@WillAyd Indeed, I've seen a abstract properties that shouldn't have appeared in docs page. But I thought it is a problem of my local environment. (I first built the document) Thanks to @jorisvandenbossche, I hid it. |
Added example cases and more details to note. As you know, there may be some mistakes because of my lack of English. If so, Please let me know:) |
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.
Minor edits. There is also a note in the docstring to "See DataFrame.to_excel for typical usage" Can you instead create a "See Also" section that references that method?
pandas/io/excel.py
Outdated
@@ -824,8 +824,56 @@ class ExcelWriter(object): | |||
|
|||
Notes | |||
----- | |||
None of methods and properties are considered public. |
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.
"None of methods" -> "None of the methods"
pandas/io/excel.py
Outdated
>>> with ExcelWriter('path_to_file.xlsx') as writer: | ||
... df.to_excel(writer) | ||
|
||
If you want to set engine that can manipulate Excel, |
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.
I think this second example is better served in to_excel
as it generic functionality. Would be OK if you removed here and added that to the to_excel
docs in a separate change
pandas/io/excel.py
Outdated
|
||
Examples | ||
-------- | ||
Using ExcelWriter, some settings can be added. |
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.
Remove this line
pandas/io/excel.py
Outdated
-------- | ||
Using ExcelWriter, some settings can be added. | ||
|
||
Default usage. |
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.
Instead of a "." use ":"
pandas/io/excel.py
Outdated
|
||
You can set date format or datetime format | ||
|
||
>>> with ExcelWriter('path_to_file.xlsx', |
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.
I am actually surprised that we allow date / date time formatting with ExcelWriter but don't have the same usage in to_excel
- if you are up to it aligning that functionality would be ideal (separate change)
pandas/io/excel.py
Outdated
>>> with ExcelWriter('path_to_file.xlsx', engine='openpyxl') as writer: | ||
... df.to_excel(writer) | ||
|
||
In order to write separate DataFrames to separate sheets |
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.
Just say "To write to separate sheets in a single file:"
pandas/io/excel.py
Outdated
datetime_format='YYYY-MM-DD HH:MM:SS') as writer: | ||
... df.to_excel(writer) | ||
|
||
It also supports append mode. |
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 also append to an existing Excel file:"
I do not know why the Travis CI build failed. Where should i look to fix it? |
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.
The test failure is because you changed pd.ExcelWriter
to ExcelWriter
in the example so Python doesn't know what you are referencing. If you revert that back should be OK (couple other edits needed as commented)
pandas/core/generic.py
Outdated
>>> with ExcelWriter('output2.xlsx', engine='openpyxl') as writer: | ||
... df2.to_excel(writer) | ||
|
||
You can set date format or datetime format: |
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.
Delete this example (keywords here are only applicable to ExcelWriter
)
pandas/core/generic.py
Outdated
... df1.to_excel(writer, sheet_name='Sheet_name_1') | ||
... df2.to_excel(writer, sheet_name='Sheet_name_2') | ||
|
||
If you want to set engine that can manipulate Excel, |
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.
Don't use ExcelWriter
here - just use to_excel
. Also move this example up above the one preceding it
Hello @newinh! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 22, 2018 at 09:30 Hours UTC |
* Also Update some examples of to_excel method
05884a7
to
04b59a5
Compare
pandas/io/excel.py
Outdated
You can also append to an existing Excel file: | ||
|
||
>>> with ExcelWriter('path_to_file.xlsx', mode='a') as writer: | ||
... df.to_excel(writer) |
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.
I would add here a sheet name? (I think you typically want to add a new sheet to an existing file?)
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.
It seems more natural to do that:)
pandas/core/generic.py
Outdated
@@ -1917,18 +1917,24 @@ def _repr_latex_(self): | |||
... columns=['col 1', 'col 2']) | |||
>>> df1.to_excel("output.xlsx") | |||
|
|||
If you want to set engine that can manipulate Excel, | |||
pass keyword argument named engine. Actually | |||
engine is automatically chosen by file extension: |
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.
Suggestion with some changed language:
To set the library that used to write the Excel file, you can pass the `engine` keyword (the default engine is automatically chosen depending on the file extension):
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.
Minor comment, looks good to me!
pandas/io/excel.py
Outdated
>>> with ExcelWriter('path_to_file.xlsx', mode='a') as writer: | ||
... df.to_excel(writer, sheet_name='Sheet3') | ||
|
||
.. versionadded:: 0.24.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.
I think this one can be removed
pandas/core/generic.py
Outdated
>>> writer.save() | ||
>>> with pd.ExcelWriter('output.xlsx') as writer: | ||
... df1.to_excel(writer, sheet_name='Sheet_name_1') | ||
... df2 = df1.copy() |
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 do this copy outside of the context manager? On initial glance I assumed it to be some requirement with the context manager itself, though that's clearly not the case
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.
I think this looks good and slightly prefer the example with append mode but am largely indifferent.
@jorisvandenbossche merge when satisfied.
@WillAyd what do you mean exactly? |
Your last comment asked to remove a piece that I would slightly prefer to keep in, but not going to lose sleep over it if you think its superfluous and still want to remove 👍 |
thanks @newinh |
git diff upstream/master -u -- "*.py" | flake8 --diff