-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pandas.DataFrame.any docstring #20217
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
Changes from 2 commits
f514443
140b164
d6214c1
0ab88c0
e171319
74db002
f567b78
39ac181
9314366
9646f7b
4579eea
9b971fd
484c409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7522,8 +7522,7 @@ def _add_numeric_operations(cls): | |
|
||
cls.any = _make_logical_function( | ||
cls, 'any', name, name2, axis_descr, | ||
'Return whether any element is True over requested axis', | ||
nanops.nanany) | ||
_any_desc, nanops.nanany, _any_examples, _any_also) | ||
cls.all = _make_logical_function( | ||
cls, 'all', name, name2, axis_descr, | ||
'Return whether all elements are True over requested axis', | ||
|
@@ -7784,25 +7783,29 @@ def _doc_parms(cls): | |
%(outname)s : %(name1)s or %(name2)s (if level specified)\n""" | ||
|
||
_bool_doc = """ | ||
|
||
%(desc)s | ||
|
||
Parameters | ||
---------- | ||
axis : %(axis_descr)s | ||
axis : int, default 0 | ||
Select the axis which can be 0 for indices and 1 for columns. | ||
skipna : boolean, default True | ||
Exclude NA/null values. If an entire row/column is NA, the result | ||
will be NA | ||
will be NA. | ||
level : int or level name, default None | ||
If the axis is a MultiIndex (hierarchical), count along a | ||
particular level, collapsing into a %(name1)s | ||
particular level, collapsing into a %(name1)s. | ||
bool_only : boolean, default None | ||
Include only boolean columns. If None, will attempt to use everything, | ||
then use only boolean data. Not implemented for Series. | ||
|
||
Returns | ||
------- | ||
%(outname)s : %(name1)s or %(name2)s (if level specified)\n""" | ||
%(outname)s : %(name1)s or %(name2)s (if level specified) | ||
|
||
%(examples)s | ||
%(see_also)s | ||
""" | ||
|
||
_cnum_doc = """ | ||
|
||
|
@@ -7825,6 +7828,49 @@ def _doc_parms(cls): | |
|
||
""" | ||
|
||
_any_also = """\ | ||
See Also | ||
-------- | ||
pandas.DataFrame.all : Return whether all elements are True \ | ||
over requested axis.""" | ||
|
||
_any_desc = """\ | ||
Return whether any element is True over requested axis. | ||
|
||
One dimensional pandas.Series having boolean values will be returned. \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pandas.Series -> Series There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also say "boolean Series" instead of "Series having boolean values" |
||
Unlike pandas.DataFrame.all, pandas.DataFrame.any performs OR operation; \ | ||
in other word, if any of the values along the specified axis is True, \ | ||
pandas.DataFrame.any will return True.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also mention here something that for Series the return value is a single boolean value? |
||
|
||
_any_examples = """\ | ||
Examples | ||
-------- | ||
By default, any from an empty DataFrame is empty Series:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No double colon, just a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomAugspurger according to this documentation, double colon is required to show code samples. |
||
|
||
>> pd.DataFrame([]).any() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Three There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomAugspurger , you mean, without double-colon and three |
||
Series([], dtype: bool) | ||
|
||
Non-boolean values will always give True:: | ||
|
||
>> pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}).any() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. |
||
A True | ||
B True | ||
dtype: bool | ||
|
||
It is performing OR along the specified axis:: | ||
|
||
>> pd.DataFrame({"A": [1, False, 3], "B": [4, 5, 6]}).any(axis=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
0 True | ||
1 True | ||
2 True | ||
dtype: bool | ||
|
||
>> pd.DataFrame({"A": [1, False, 3], "B": [4, False, 6]}).any(axis=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. |
||
0 True | ||
1 False | ||
2 True | ||
dtype: bool | ||
""" | ||
|
||
_sum_examples = """\ | ||
Examples | ||
|
@@ -7985,9 +8031,11 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs): | |
return set_function_name(cum_func, name, cls) | ||
|
||
|
||
def _make_logical_function(cls, name, name1, name2, axis_descr, desc, f): | ||
def _make_logical_function(cls, name, name1, name2, axis_descr, desc, f, | ||
examples='', see_also=''): | ||
|
||
@Substitution(outname=name, desc=desc, name1=name1, name2=name2, | ||
axis_descr=axis_descr) | ||
axis_descr=axis_descr, examples=examples, see_also=see_also) | ||
@Appender(_bool_doc) | ||
def logical_func(self, axis=None, bool_only=None, skipna=None, level=None, | ||
**kwargs): | ||
|
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 don't think you need the trailing
\
here do you?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.
to be clear, you do need the one on the first line, jsut not these.
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, and the same for the ones below 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.
@TomAugspurger if I don't put
\
, line becomes longer than 79 characters and it isn't passinggit diff origin/master -u -- "*.py" | flake8 --diff
validation...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 want them, else we get long lines in the text docstring liek
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.
@TomAugspurger & @jorisvandenbossche , let's say I removed
\
and , then the result ofgit diff origin/master -u -- "*.py" | flake8 --diff
is going to bepandas/core/generic.py:7834:80: E501 line too long (83 > 79 characters)
, since the line ispandas.DataFrame.all : Return whether all elements are True over requested axis.
- I don't want to break the line with\n
, instead, I'm using\
. There is exactly same reason behind the cases I used\
.