Skip to content

DOC: update the pandas.DataFrame.plot.pie docstring #20133

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
Mar 17, 2018
Merged

DOC: update the pandas.DataFrame.plot.pie docstring #20133

merged 3 commits into from
Mar 17, 2018

Conversation

dim1tri
Copy link
Contributor

@dim1tri dim1tri commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py pandas.DataFrame.plot.pie
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

Docstring for "pandas.DataFrame.plot.pie" correct. :)

Copy link

@Renton2017 Renton2017 left a comment

Choose a reason for hiding this comment

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

Well the code is OK. I have a specific doubt on **kwds : optional. I would delete the asterisks and leave like kwds

Copy link

@Renton2017 Renton2017 left a comment

Choose a reason for hiding this comment

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

Well the code is OK. I have a specific doubt on **kwds : optional. I would delete the asterisks and leave like kwds

@dim1tri
Copy link
Contributor Author

dim1tri commented Mar 10, 2018

@Renton2017, could you please make a reference to a line number?

@dukebody
Copy link
Contributor

The keyword arguments must be mentioned in the docstring as **kwargs.

@dukebody
Copy link
Contributor

Can you include a screenshot of the generated html?

@Renton2017
Copy link

Hi Dimitri,

on line 2844 **kwds : optional
meanwhile on line 2849 kwds : optional

They cannot be true both!

y : str or int, optional
Label or position.
If not provided, ``subplots=True`` argument must be passed.
kwds : optional
Copy link
Contributor

Choose a reason for hiding this comment

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

Use **kwds : optional, not kwds : optional, even if the validation script complains about it.

`**kwds` : optional
y : str or int, optional
Label or position.
If not provided, ``subplots=True`` argument must be passed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Really? What happens if we don't pass subplots=True and we don't pass a y argument? Does it raise an error? What does the subplots=True argument change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. This error is raised:
ValueError: pie requires either y column or 'subplots=True'
with subplots=True, pie() returns an array of plots for all columns


See Also
--------
:meth:`pandas.Series.plot.pie` : Generate a pie plot for a Serie.
Copy link
Contributor

Choose a reason for hiding this comment

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

pie plot for a Series, in plural

Column to plot.
`**kwds` : optional
y : str or int, optional
Label or position.
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the Column to plot part important. What about Label of position indicating the column to plot?

Examples
--------

.. plot::
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some text above explaining what is the example about in plain English? Also, perhaps you want to create different plots for different y values to show how the plot changes when changing the y argument.

@pep8speaks
Copy link

pep8speaks commented Mar 10, 2018

Hello @dim1tri! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on March 16, 2018 at 21:46 Hours UTC


A pie plot is a representation of the distribution of numerical data
in a DataFrame column. This function wraps the `matplotlib.pyplot.pie`
function for specified column. If no column reference is passed and
Copy link
Contributor

Choose a reason for hiding this comment

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

for the specified column


A pie plot is a representation of the distribution of numerical data
in a DataFrame column. This function wraps the `matplotlib.pyplot.pie`
function for specified column. If no column reference is passed and
Copy link
Contributor

Choose a reason for hiding this comment

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

refer to 'y' here (its the column reference)

y : str or int, optional
Label or position of the column to plot.
If not provided, ``subplots=True`` argument must be passed.
**kwds : optional
Copy link
Contributor

Choose a reason for hiding this comment

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

no ** on kwds

Copy link
Contributor

Choose a reason for hiding this comment

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

@jreback there is a huge confusion here. @datapythonista said we DO want ** on kwds and they are modifying the validation script to accept it. Now you say we don't want it. Can we make a decision about this?

Copy link
Member

Choose a reason for hiding this comment

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

@jreback we decided to keep them

Copy link
Member

Choose a reason for hiding this comment

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

@jreback I thought the consensus was to have them. We've got a bug in the script that was validating the opposite, which created some confusion, but in the documentation we've got that they should have the ** in the name.

If there is no final decision, I'd accept both. I think it should be quite easy to use validate_docstrings.py to detect all the ones that have, or not have them. And we can quickly change all them later on.

in a DataFrame column. This function wraps the `matplotlib.pyplot.pie`
function for specified column. If no column reference is passed and
``subplots`` argument is set to ``True``, an np.array of plots for
all DataFrame columns will be returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

for all the DataFrame columns

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.

Thanks for the PR! Added some comments

A pie plot is a representation of the distribution of numerical data
in a DataFrame column. This function wraps the `matplotlib.pyplot.pie`
function for specified column. If no column reference is passed and
``subplots`` argument is set to ``True``, an np.array of plots for
Copy link
Member

Choose a reason for hiding this comment

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

you can use single backticks for 'subplots' (because it is a reference to a parameter)

y : label or position, optional
Column to plot.
`**kwds` : optional
y : str or int, optional
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit a corner case as well, but in another PR we decide to keep the 'label', as 'str' can actually be too strict on the column name (column names can be other things as strings) ..

Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.

Returns
-------
axes : matplotlib.AxesSubplot or np.array of them
axes : matplotlib.AxesSubplot or np.array of them.
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 explain here when an array is returned?


See Also
--------
:meth:`pandas.Series.plot.pie` : Generate a pie plot for a Series.
Copy link
Member

Choose a reason for hiding this comment

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

You can leave out the :meth:` part here (the link is automatically made by numpydoc

I would also add the see also to matplotlib.pyplot.pie


>>> df = pd.DataFrame({'mass': [0.330, 4.87 , 5.97],
... 'radius': [2439.7, 6051.8, 6378.1]})
>>> plot = df.plot.pie(y='mass', labels=['Mercury', 'Venus', 'Earth'])
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also add an example with the subplots argument?

`**kwds` : optional
y : str or int, optional
Label or position of the column to plot.
If not provided, ``subplots=True`` argument must be passed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Improvement proposal: If not provided, the ``subplots=True`` argument must be passed. In this case, a subplot will be created for every column of the DataFrame.


Examples
--------
In the example below we have a DataFrame with the information about
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a matter of style, but I'd say:

Given a DataFrame with information about some planets mass and radius, create a pie plot of their masses:

Because the fact that it is an example can be determined from the section it is in, and the fact that we pass the 'mass' column to the pie method can be seen in the code itself.

What about another example without specifying the y argument?

@dukebody
Copy link
Contributor

@dim1tri please ping me if you have issues fixing the merge conflicts.

@dukebody
Copy link
Contributor

@dim1tri is there something we can do to help you with this PR?

* Aspect Ratio
* Use index

[ci skip]
@codecov
Copy link

codecov bot commented Mar 16, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@3561580). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20133   +/-   ##
=========================================
  Coverage          ?   91.72%           
=========================================
  Files             ?      150           
  Lines             ?    49152           
  Branches          ?        0           
=========================================
  Hits              ?    45086           
  Misses            ?     4066           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.11% <ø> (?)
#single 41.84% <ø> (?)
Impacted Files Coverage Δ
pandas/plotting/_core.py 82.23% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3561580...c49fbb3. Read the comment docs.

@TomAugspurger
Copy link
Contributor

Updated

Fixed the aspect ratio on the plots, added a subplots=True example, and used the index instead of labels.

fireshot capture 006 - pandas dataframe plot pie pandas 0 _ - file____users_taugspurger_sandbox_

@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Mar 16, 2018
@jorisvandenbossche jorisvandenbossche merged commit e9a6735 into pandas-dev:master Mar 17, 2018
@jorisvandenbossche
Copy link
Member

@dim1tri Thanks!

@SimonBaron
Copy link
Contributor

I have wanted to ask for a while, but never sure where.. Is this documentation page a joke? Is it intentionally trolling? It is, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants