-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Clarified and expanded describe documentation #14995
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: Clarified and expanded describe documentation #14995
Conversation
Current coverage is 84.77% (diff: 100%)@@ master #14995 diff @@
==========================================
Files 145 145
Lines 51090 51129 +39
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43316 43343 +27
- Misses 7774 7786 +12
Partials 0 0
|
@@ -5201,60 +5201,209 @@ def abs(self): | |||
""" | |||
return np.abs(self) | |||
|
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.
why are you redefining things here???
this is just a very small edit to the _shared_docs['describe']
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.
@palewire Typically we reuse docstring on several places, eg for Series/DataFrame/Panel definitions, that's the reason of the use of _shared_docs
.
But, @jreback, was just looking in this specific case, this is the only place where this docstring is used, so it is actually not really needed to put it in _shared_docs
I think? (maybe a leftover from when the definitions where in multiple places)
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.
this is used in both Series & DataFrame, so needs to stay as shared docs
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.
But it is only defined here (the function is not redefined in series or dataframe, so the shared docstrings is not used anywhere else)
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.
oh, ok then.
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'd be happy to try that correction, though I think it's worth pointing out that was a pre-existing bug in the describe documentation and nothing introduced by this pull request. Could you point me to example of a similar shared method I could model the fix on?
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.
as I said, pretty much any function in series or dataframe that has a shared doc
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 not sure if it is worth including describe
defs in both Series and DataFrame (that of course just simply passes args to its super method), just for customizing this single word. For docstrings that include more variables to be changed, that would be OK. But IMO in this case it is not worth it.
It's a bit of a problem with how our handling of shared docstrings currently works, as it does not work perfectly for all cases that we use it for. But having a better approach for functions like this (i.e. functions that have only a definition in generic, and not in series/frame.py) is a whole other/larger issue that can be left for another issue/PR to discuss.
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.
@jorisvandenbossche, if that's how you feel I can hold off on pursuing that route. Are there other modifications you'd like to see?
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.
@jreback are you OK with this in its current form (so not using the _shared_docs
). I agree that we should try to have accurate docstrings for both Series and DataFrame making use of our decorator machinery, but in this case it did not make use of that machinery.
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.
Nice examples! Thanks for that
Returns | ||
------- | ||
summary: %(klass)s of summary statistics | ||
For ``numeric`` data, the result's index will include ``count``, |
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 leave these details in the notes section as it was before. Reason is that otherwise it 'takes a long time' before you get to the 'Parameters'. But maybe we could include in the previous sentence something like "Output format depends on the data type, see Notes for more details"
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.
Got it. I'll move it back down. I had decided to move it up after consulting numpy's HOWTO, which says that Notes should be reserved for background information. But if pandas is consistent about having the extended description there instead of at the top of the docstring that seems a-okay to me. I'll move it down.
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.
Yes, to follow the numpy docstring standard, the first sentence should be shorter. And can then be followed by a longer description. But ideally this longer description is only a couple of lines, and IMO if this is longer, it should better go into Notes (as you typically want to show parameters rather prominently as well).
That your long description has to be so long is actually also an indication that the scope of your function is not well defined IMO, but that is another issue .. (and for describe as a convenience function it is OK to do something different for different dtypes)
documentation. eg. df.describe(include=['O']) | ||
- If include is the string 'all', the output column-set will | ||
match the input one. | ||
Analyzes both ``numeric`` and ``object`` series, as well |
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.
'numeric' and 'object' do not really refer to actual code or keywords in this case, so I would leave them in 'normal' text (not back tick quoted)
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.
For DataFrame (line below), you can also leave out the quotes I think (for consistency, although we certainly are not consistent in all places)
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.
Got it. I struggled with how to properly use the single and double backticks. I tried to model my behavior on the recommendations of the numpy HOWTO.
I'll take another pass through and try to be more sparing with their use.
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.
We follow the suggestion for the numpy howto to refer to keywords with single backticks, but use typically double backticks for 'code fragments' or other variables/functions apart from keywords.
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.
Got it. I will take another pass to try to tighten things up to meet your standard.
objects submit the data type ``object``. Strings | ||
can also be used in the style of | ||
`select_dtypes` (e.g. df.describe(include=['O'])) | ||
exclude : None (default) or a list of dtypes or strings, optional, |
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.
Not a strong opinion here, but I also kind of liked the combined explanation. What is most clear (less repetition vs being more explicit) is always a bit of a difficult/subjective balance ..
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 agree this is a balancing act. I decided to separate them after consulting the source code, where I found that include and exclude actually have slightly different behavior. From what I can tell, all
is not an acceptable input for exclude. Separating them also allowed me space to try to write more explicit descriptions that contrast the two keywords.
… to the Notes section
I've just pushed an update that tried to address your requests, @jorisvandenbossche. Please let me know if there's more I can do. |
""" | ||
Generates descriptive statistics that summarize the central tendency, | ||
dispersion and shape of a dataset's distribution, excluding | ||
``NaN`` values. | ||
|
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 the sentence from the notes with something like "Analyzes both numeric and object series, as well
as DataFrame column sets of mixed data types." + that output depends on data type + refer to notes for more details on this
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.
Will do.
documentation. eg. df.describe(include=['O']) | ||
- If include is the string 'all', the output column-set will | ||
match the input one. | ||
percentiles : list of numbers, optional |
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.
Strictly spoken, the change from array-like to list of numbers is not really a correction, as arrays are also accepted, but I agree list is more clear to users. Maybe "list-like of numbers"?
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.
Will do.
fall between 0 and 1. The default is | ||
``[.25, .5, .75]``, which returns the 25th, 50th, and | ||
75th percentiles. | ||
include : None (default), 'all', or list of dtypes or strings, optional |
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.
We typically put the "default None" at the end.
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 will flip them to the bottom.
for `Series`. Here are the options: | ||
|
||
- None (default). The result will include all numeric columns. | ||
- 'all'. All columns on the input will be included in the output. |
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.
" on the input" -> "of the input" ?
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.
That is my mistake. I will correct it.
|
||
Returns | ||
------- | ||
summary: %(klass)s of summary statistics |
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.
NDFrame -> Series/DataFrame
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.
Will do.
``mean``, ``std``, ``min``, ``max`` as well as lower, ``50`` and | ||
upper percentiles. By default the lower percentile is ``25`` and the | ||
upper percentile is ``75``. The ``50`` percentile is typically the | ||
same as the median. |
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 50
percentile is typically the same as the median." -> when is this 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 was thinking of the alternative methods of returning medians when there are an even number of values that might result in differing expectations among users. But that's probably unnecessary. I will remove the qualification.
among those with the highest count. | ||
|
||
The include, exclude arguments are ignored for Series. | ||
For mixed data types provided via a DataFrame, the result will | ||
include a union of attributes of each type. |
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.
Maybe mention first that the default is only to show numeric columns. And if, using include='all'
, different types are included, then the index is union of the attributes of each type.
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.
Good point. I think that will make things more clear. I will change it.
@jorisvandenbossche, I have just pushed a number of new changes to try to conform with your second round of requests. Please let me know if there is more I can do. Thank you for your thorough review. |
@palewire Looks good! You only have a few PEP8 issues (which causes travis to fail):
If those are fixed this can be merged! |
I am ok with this as the docs for series are so close to dataframe its fine to combine. |
@jorisvandenbossche I have just now made and pushed the PEP8 corrections you requested. |
…ition/pandas into describe-docs
@palewire Thanks! |
git diff upstream/master | flake8 --diff
As discussed in #14483.