Skip to content

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

Merged
merged 13 commits into from Mar 12, 2018
Binary file added doc/source/savefig/andrews_curve_winter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/andrews_curves.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/area_plot_stacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/area_plot_unstacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/autocorrelation_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/bar_plot_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/bar_plot_multi_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/bar_plot_stacked_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/barh_plot_stacked_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/basics_assign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/bollinger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/bootstrap_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/box_new_colorize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/box_new_kwargs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/box_plot_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/box_plot_ex2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/box_plot_ex3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/box_plot_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/boxplot_groupby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/compare_interpolations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/cubehelix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/cubehelix_cm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/df_pie_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/df_plot_xy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/errorbar_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/savefig/ewma_ex.png
Binary file added doc/source/savefig/expanding_mean_frame.png
Binary file added doc/source/savefig/frame_hist_ex.png
Binary file added doc/source/savefig/frame_plot_basic.png
Binary file added doc/source/savefig/frame_plot_basic_noleg.png
Binary file added doc/source/savefig/frame_plot_secondary_y.png
Binary file added doc/source/savefig/frame_plot_subplots.png
Binary file added doc/source/savefig/frame_plot_subplots_layout.png
Binary file added doc/source/savefig/greens.png
Binary file added doc/source/savefig/groupby_boxplot.png
Binary file added doc/source/savefig/groupby_boxplot_vis.png
Binary file added doc/source/savefig/groupby_transform_plot.png
Binary file added doc/source/savefig/grouped_hist.png
Binary file added doc/source/savefig/hexbin_plot.png
Binary file added doc/source/savefig/hexbin_plot_agg.png
Binary file added doc/source/savefig/hist_new.png
Binary file added doc/source/savefig/hist_new_kwargs.png
Binary file added doc/source/savefig/hist_new_stacked.png
Binary file added doc/source/savefig/hist_plot_ex.png
Binary file added doc/source/savefig/kde_plot.png
Binary file added doc/source/savefig/lag_plot.png
Binary file added doc/source/savefig/line_plot_table_data.png
Binary file added doc/source/savefig/line_plot_table_describe.png
Binary file added doc/source/savefig/line_plot_table_true.png
Binary file added doc/source/savefig/merge_on_index_and_column.png
Binary file added doc/source/savefig/merging_append1.png
Binary file added doc/source/savefig/merging_append2.png
Binary file added doc/source/savefig/merging_append3.png
Binary file added doc/source/savefig/merging_append_dits.png
Binary file added doc/source/savefig/merging_combine_first.png
Binary file added doc/source/savefig/merging_concat_axis1.png
Binary file added doc/source/savefig/merging_concat_axis1_inner.png
Binary file added doc/source/savefig/merging_concat_basic.png
Binary file added doc/source/savefig/merging_concat_dict.png
Binary file added doc/source/savefig/merging_concat_dict_keys.png
Binary file added doc/source/savefig/merging_concat_group_keys2.png
Binary file added doc/source/savefig/merging_concat_keys.png
Binary file added doc/source/savefig/merging_concat_mixed_ndim.png
Binary file added doc/source/savefig/merging_join.png
Binary file added doc/source/savefig/merging_join_inner.png
Binary file added doc/source/savefig/merging_join_key_columns.png
Binary file added doc/source/savefig/merging_join_multi_df.png
Binary file added doc/source/savefig/merging_join_multikeys.png
Binary file added doc/source/savefig/merging_join_outer.png
Binary file added doc/source/savefig/merging_merge_index_inner.png
Binary file added doc/source/savefig/merging_merge_index_outer.png
Binary file added doc/source/savefig/merging_merge_key_columns.png
Binary file added doc/source/savefig/merging_merge_on_key.png
Binary file added doc/source/savefig/merging_merge_on_key_dup.png
Binary file added doc/source/savefig/merging_merge_on_key_inner.png
Binary file added doc/source/savefig/merging_merge_on_key_left.png
Binary file added doc/source/savefig/merging_merge_on_key_outer.png
Binary file added doc/source/savefig/merging_merge_on_key_right.png
Binary file added doc/source/savefig/merging_merge_overlapped.png
Binary file added doc/source/savefig/merging_update.png
Binary file added doc/source/savefig/parallel_coordinates.png
Binary file added doc/source/savefig/parallel_gist_rainbow.png
Binary file added doc/source/savefig/quartile_boxplot.png
Binary file added doc/source/savefig/radviz.png
Binary file added doc/source/savefig/rolling_apply_ex.png
Binary file added doc/source/savefig/rolling_corr_pairwise_ex.png
Binary file added doc/source/savefig/rolling_mean_ex.png
Binary file added doc/source/savefig/rolling_mean_frame.png
Binary file added doc/source/savefig/scatter_matrix_kde.png
Binary file added doc/source/savefig/scatter_plot.png
Binary file added doc/source/savefig/scatter_plot_bubble.png
Binary file added doc/source/savefig/scatter_plot_colored.png
Binary file added doc/source/savefig/scatter_plot_repeated.png
Binary file added doc/source/savefig/ser_plot_suppress.png
Binary file added doc/source/savefig/ser_plot_suppress_context.png
Binary file added doc/source/savefig/ser_plot_suppress_parm.png
Binary file added doc/source/savefig/series_interpolate.png
Binary file added doc/source/savefig/series_pie_plot.png
Binary file added doc/source/savefig/series_pie_plot_options.png
Binary file added doc/source/savefig/series_pie_plot_semi.png
Binary file added doc/source/savefig/series_plot_basic.png
Binary file added doc/source/savefig/series_plot_basic2.png
Binary file added doc/source/savefig/series_plot_logy.png
Binary file added doc/source/savefig/series_plot_multi.png
Binary file added doc/source/savefig/series_plot_secondary_y.png
66 changes: 57 additions & 9 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 = """

Expand All @@ -7825,6 +7828,49 @@ def _doc_parms(cls):

"""

_any_also = """\
See Also
--------
pandas.DataFrame.all : Return whether all elements are True \
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Author

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 passing git diff origin/master -u -- "*.py" | flake8 --diff validation...

Copy link
Contributor

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

One dimensional boolean pandas.Series is returned. 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.

Copy link
Author

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 of git diff origin/master -u -- "*.py" | flake8 --diff is going to be pandas/core/generic.py:7834:80: E501 line too long (83 > 79 characters), since the line is pandas.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 \.

over requested axis."""

_any_desc = """\
Return whether any element is True over requested axis.

One dimensional pandas.Series having boolean values will be returned. \
Copy link
Member

Choose a reason for hiding this comment

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

pandas.Series -> Series

Copy link
Member

Choose a reason for hiding this comment

The 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."""
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 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::
Copy link
Contributor

Choose a reason for hiding this comment

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

No double colon, just a .

Copy link
Author

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Three >. Doesn't need to be indented.

Copy link
Author

Choose a reason for hiding this comment

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

@TomAugspurger , you mean, without double-colon and three >, is it going to show code samples as required?

Series([], dtype: bool)

Non-boolean values will always give True::

>> pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}).any()
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

same.

0 True
1 False
2 True
dtype: bool
"""

_sum_examples = """\
Examples
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,8 @@ def result_to_bool(result):
@Substitution(name='groupby')
@Appender(_doc_template)
def any(self, skipna=True):
"""Returns True if any value in the group is truthful, else False
"""
Returns True if any value in the group is truthful, else False

Parameters
----------
Expand Down