-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
DOC: Updating operators docstrings #20415
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 14 commits
acab08e 1818aeb 86cfd56 b68b61f 13fed5f 8bdbc14 4668c5f e6eb9b9 db143c4 33ff1e4 e138d92 50e9d98 aa016fd c2cc037 644273b 240a502 bbcdcbe a33f003 70950c0 6bcb9b9 e7da1e9 20cbec1 722ae81 4580f7a 49c7b82 1e4e450 ec71a04 25129ff d344688 eaaee0d e777e87 6879e89 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 |
|---|---|---|
| | @@ -493,28 +493,23 @@ def _get_op_name(op, special): | |
| # Comparison Operators | ||
| 'eq': {'op': '==', | ||
| 'desc': 'Equal to', | ||
| 'reverse': None, | ||
| 'df_examples': None}, | ||
| 'reverse': None}, | ||
| 'ne': {'op': '!=', | ||
| 'desc': 'Not equal to', | ||
| 'reverse': None, | ||
| 'df_examples': None}, | ||
| 'reverse': None}, | ||
| 'lt': {'op': '<', | ||
| 'desc': 'Less than', | ||
| 'reverse': None, | ||
| 'df_examples': None}, | ||
| 'reverse': None}, | ||
| 'le': {'op': '<=', | ||
| 'desc': 'Less than or equal to', | ||
| 'reverse': None, | ||
| 'df_examples': None}, | ||
| 'reverse': None}, | ||
| 'gt': {'op': '>', | ||
| 'desc': 'Greater than', | ||
| 'reverse': None, | ||
| 'df_examples': None}, | ||
| 'reverse': None}, | ||
| 'ge': {'op': '>=', | ||
| 'desc': 'Greater than or equal to', | ||
| 'reverse': None, | ||
| 'df_examples': None}} | ||
| 'reverse': None} | ||
| } | ||
| | ||
| _op_names = list(_op_descriptions.keys()) | ||
| for key in _op_names: | ||
| | @@ -640,6 +635,139 @@ def _get_op_name(op, special): | |
| DataFrame.{reverse} | ||
| """ | ||
| | ||
| _flex_comp_doc_FRAME = """ | ||
| {desc} of dataframe and other, element-wise (binary operator `{op_name}`). | ||
| | ||
| Among flexible wrappers (`eq`, `ne`, `le`, `lt`, `ge`, `gt`) to comparison | ||
| operators. | ||
| | ||
| Equivalent to `==`, `=!`, `<=`, `<`, `>=`, `>` with support to choose axis | ||
| (rows or columns) and level for comparison. | ||
| | ||
| Parameters | ||
| ---------- | ||
| other : scalar, sequence, Series, or DataFrame | ||
| Any single or multiple element data structure, or list-like object. | ||
| axis : {{0 or 'index', 1 or 'columns'}}, default 'columns' | ||
| Whether to compare by the index (0 or 'index') or columns | ||
| (1 or 'columns'). | ||
| level : int or object | ||
| Broadcast across a level, matching Index values on the passed | ||
| MultiIndex level. | ||
| | ||
| Returns | ||
| ------- | ||
| DataFrame of bool | ||
| Result of the comparison. | ||
| | ||
| See Also | ||
| -------- | ||
| DataFrame.eq : Compare DataFrames for equality elementwise | ||
| DataFrame.ne : Compare DataFrames for inequality elementwise | ||
| DataFrame.le : Compare DataFrames for less than inequality | ||
| or equality elementwise | ||
| DataFrame.lt : Compare DataFrames for strictly less than | ||
| inequality elementwise | ||
| DataFrame.ge : Compare DataFrames for greater than inequality | ||
| or equality elementwise | ||
| DataFrame.gt : Compare DataFrames for strictly greater than | ||
| inequality elementwise | ||
| | ||
| Notes | ||
| -------- | ||
| Mismatched indices will be unioned together. | ||
datapythonista marked this conversation as resolved. Show resolved Hide resolved | ||
| `NaN` values are considered different (i.e. `NaN` != `NaN`). | ||
| | ||
| Examples | ||
| -------- | ||
| >>> df = pd.DataFrame({{'cost': [250, 150, 100], | ||
| ... 'revenue': [100, 250, 300]}}, | ||
datapythonista marked this conversation as resolved. Show resolved Hide resolved | ||
| ... index = ['A', 'B', 'C']) | ||
| >>> df | ||
| cost revenue | ||
| Contributor 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 we turn on doc-tests for this? | ||
| A 250 100 | ||
| B 150 250 | ||
| C 100 300 | ||
| | ||
| Compare to a scalar and operator version which return the same | ||
| results. | ||
datapythonista marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| >>> df == 100 | ||
| cost revenue | ||
| A False True | ||
| B False False | ||
| C True False | ||
| >>> df.eq(100) | ||
| cost revenue | ||
| A False True | ||
| B False False | ||
| C True False | ||
| | ||
| Compare to a list and Series by axis and operator version. | ||
| | ||
| >>> df != [100, 250, 300] | ||
| cost revenue | ||
| A True False | ||
| B True False | ||
| C True False | ||
| >>> df.ne([100, 250, 300], axis='index') | ||
| cost revenue | ||
| A True False | ||
| B True False | ||
| C True False | ||
| >>> df != pd.Series([100, 250, 300]) | ||
datapythonista marked this conversation as resolved. Show resolved Hide resolved | ||
| cost revenue 0 1 2 | ||
| A True True True True True | ||
| B True True True True True | ||
| C True True True True True | ||
| >>> df.ne(pd.Series([100, 250, 300]), axis='columns') | ||
| cost revenue 0 1 2 | ||
| A True True True True True | ||
| B True True True True True | ||
| C True True True True True | ||
| | ||
| Compare to a DataFrame of different shape. | ||
| | ||
| >>> other = pd.DataFrame({{'revenue': [300, 250, 100, 150]}}, | ||
| ... index = ['A', 'B', 'C', 'D']) | ||
| ||
| >>> other | ||
| revenue | ||
| A 300 | ||
| B 250 | ||
| C 100 | ||
| D 150 | ||
| >>> df.gt(other) | ||
| cost revenue | ||
| A False False | ||
| B False False | ||
| C False True | ||
| D False False | ||
datapythonista marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| Compare to a MultiIndex by level. | ||
| | ||
| >>> df_multindex = pd.DataFrame({{'cost': [250, 150, 100, 150, 300, 220], | ||
| ... 'revenue': [100, 250, 300, 200, 175, 225]}}, | ||
| ... index = [['Q1', 'Q1', 'Q1', 'Q2', 'Q2', 'Q2'], | ||
| ||
| ... ['A', 'B', 'C', 'A', 'B' ,'C']]) | ||
| >>> df_multindex | ||
| cost revenue | ||
| Q1 A 250 100 | ||
| B 150 250 | ||
| C 100 300 | ||
| Q2 A 150 200 | ||
| B 300 175 | ||
| C 220 225 | ||
| | ||
| >>> df.le(df_multindex, level=1) | ||
| cost revenue | ||
| Q1 A True True | ||
| B True True | ||
| C True True | ||
| Q2 A False True | ||
| B True False | ||
| C True False | ||
| """ | ||
| | ||
| Member 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 think we need to explain what's going on here. And I'd probably set The blank line after the docstring is not required. Member 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. Has this been resolved? Member 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 add this explanation? So users can understand in an easier way what we are showing here. | ||
| _flex_doc_PANEL = """ | ||
| {desc} of series and other, element-wise (binary operator `{op_name}`). | ||
| Equivalent to ``{equiv}``. | ||
| | @@ -1764,8 +1892,14 @@ def na_op(x, y): | |
| result = mask_cmp_op(x, y, op, (np.ndarray, ABCSeries)) | ||
| return result | ||
| | ||
| @Appender('Wrapper for flexible comparison methods {name}' | ||
| .format(name=op_name)) | ||
| if op_name in _op_descriptions: | ||
| op_desc = _op_descriptions[op_name] | ||
| doc = _flex_comp_doc_FRAME.format(desc=op_desc['desc'], | ||
| op_name=op_name) | ||
| else: | ||
| doc = "Flexible wrappers to comparison methods" | ||
| | ||
| @Appender(doc) | ||
datapythonista marked this conversation as resolved. Show resolved Hide resolved | ||
| def f(self, other, axis=default_axis, level=None): | ||
| | ||
| other = _align_method_FRAME(self, other, axis) | ||
| | ||
Uh oh!
There was an error while loading. Please reload this page.