-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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 1 commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,166 +398,166 @@ def _get_op_name(op, special): | |
""" | ||
|
||
_eq_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [100, 200, 300]}, | ||
... columns=['tool', 'score']) | ||
>>> df1 = pd.DataFrame({'company': ['A', 'B', 'C'], | ||
... 'cost': [250, 150, 100], | ||
... 'revenue': [100, 250, 300]}) | ||
>>> df1 | ||
tool score | ||
0 python 100 | ||
1 r 200 | ||
2 julia 300 | ||
>>> df2 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [300, 200, 100]}, | ||
... columns=['tool', 'score']) | ||
company cost revenue | ||
0 A 250 100 | ||
1 B 150 250 | ||
2 C 100 300 | ||
>>> df2 = pd.DataFrame({'company': ['A', 'B', 'C', 'D'], | ||
... 'revenue': [300, 250, 100, 150]}) | ||
>>> df2 | ||
tool score | ||
0 python 300 | ||
1 r 200 | ||
2 julia 100 | ||
company revenue | ||
0 A 300 | ||
1 B 250 | ||
2 C 100 | ||
3 D 150 | ||
>>> df1.eq(df2) | ||
tool score | ||
0 True False | ||
1 True True | ||
2 True False | ||
company cost revenue | ||
0 True False False | ||
1 True False True | ||
2 True False False | ||
3 False False False | ||
""" | ||
|
||
_ne_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [100, 200, 300]}, | ||
... columns=['tool', 'score']) | ||
>>> df1 = pd.DataFrame({'company': ['A', 'B', 'C'], | ||
... 'cost': [250, 150, 100], | ||
... 'revenue': [100, 250, 300]}) | ||
>>> df1 | ||
tool score | ||
0 python 100 | ||
1 r 200 | ||
2 julia 300 | ||
>>> df2 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [300, 200, 100]}, | ||
... columns=['tool', 'score']) | ||
company cost revenue | ||
0 A 250 100 | ||
1 B 150 250 | ||
2 C 100 300 | ||
>>> df2 = pd.DataFrame({'company': ['A', 'B', 'C', 'D'], | ||
... 'revenue': [300, 250, 100, 150]}) | ||
>>> df2 | ||
tool score | ||
0 python 300 | ||
1 r 200 | ||
2 julia 100 | ||
company revenue | ||
0 A 300 | ||
1 B 250 | ||
2 C 100 | ||
3 D 150 | ||
>>> df1.ne(df2) | ||
tool score | ||
0 False True | ||
1 False False | ||
2 False True | ||
company cost revenue | ||
0 False True True | ||
1 False True False | ||
2 False True True | ||
3 True True True | ||
""" | ||
|
||
_lt_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [100, 200, 300]}, | ||
... columns=['tool', 'score']) | ||
>>> df1 = pd.DataFrame({'company': ['A', 'B', 'C'], | ||
... 'cost': [250, 150, 100], | ||
... 'revenue': [100, 250, 300]}) | ||
>>> df1 | ||
tool score | ||
0 python 100 | ||
1 r 200 | ||
2 julia 300 | ||
>>> df2 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [300, 200, 100]}, | ||
... columns=['tool', 'score']) | ||
company cost revenue | ||
0 A 250 100 | ||
1 B 150 250 | ||
2 C 100 300 | ||
>>> df2 = pd.DataFrame({'company': ['A', 'B', 'C', 'D'], | ||
... 'revenue': [300, 250, 100, 150]}) | ||
>>> df2 | ||
tool score | ||
0 python 300 | ||
1 r 200 | ||
2 julia 100 | ||
company revenue | ||
0 A 300 | ||
1 B 250 | ||
2 C 100 | ||
3 D 150 | ||
>>> df1.lt(df2) | ||
tool score | ||
0 False True | ||
1 False False | ||
2 False False | ||
company cost revenue | ||
0 False False True | ||
1 False False False | ||
2 False False False | ||
3 False False False | ||
""" | ||
|
||
_le_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [100, 200, 300]}, | ||
... columns=['tool', 'score']) | ||
>>> df1 = pd.DataFrame({'company': ['A', 'B', 'C'], | ||
... 'cost': [250, 150, 100], | ||
... 'revenue': [100, 250, 300]}) | ||
>>> df1 | ||
tool score | ||
0 python 100 | ||
1 r 200 | ||
2 julia 300 | ||
>>> df2 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [300, 200, 100]}, | ||
... columns=['tool', 'score']) | ||
company cost revenue | ||
0 A 250 100 | ||
1 B 150 250 | ||
2 C 100 300 | ||
>>> df2 = pd.DataFrame({'company': ['A', 'B', 'C', 'D'], | ||
... 'revenue': [300, 250, 100, 150]}) | ||
>>> df2 | ||
tool score | ||
0 python 300 | ||
1 r 200 | ||
2 julia 100 | ||
company revenue | ||
0 A 300 | ||
1 B 250 | ||
2 C 100 | ||
3 D 150 | ||
>>> df1.le(df2) | ||
tool score | ||
0 True True | ||
1 True True | ||
2 True False | ||
company cost revenue | ||
0 True False True | ||
1 True False True | ||
2 True False False | ||
3 False False False | ||
""" | ||
|
||
_gt_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [100, 200, 300]}, | ||
... columns=['tool', 'score']) | ||
>>> df1 = pd.DataFrame({'company': ['A', 'B', 'C'], | ||
... 'cost': [250, 150, 100], | ||
... 'revenue': [100, 250, 300]}) | ||
>>> df1 | ||
tool score | ||
0 python 100 | ||
1 r 200 | ||
2 julia 300 | ||
>>> df2 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [300, 200, 100]}, | ||
... columns=['tool', 'score']) | ||
company cost revenue | ||
0 A 250 100 | ||
1 B 150 250 | ||
2 C 100 300 | ||
>>> df2 = pd.DataFrame({'company': ['A', 'B', 'C', 'D'], | ||
... 'revenue': [300, 250, 100, 150]}) | ||
>>> df2 | ||
tool score | ||
0 python 300 | ||
1 r 200 | ||
2 julia 100 | ||
company revenue | ||
0 A 300 | ||
1 B 250 | ||
2 C 100 | ||
3 D 150 | ||
>>> df1.gt(df2) | ||
tool score | ||
0 False False | ||
1 False False | ||
2 False True | ||
company cost revenue | ||
0 False False False | ||
1 False False False | ||
2 False False True | ||
3 False False False | ||
""" | ||
|
||
_ge_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [100, 200, 300]}, | ||
... columns=['tool', 'score']) | ||
>>> df1 = pd.DataFrame({'company': ['A', 'B', 'C'], | ||
... 'cost': [250, 150, 100], | ||
... 'revenue': [100, 250, 300]}) | ||
>>> df1 | ||
tool score | ||
0 python 100 | ||
1 r 200 | ||
2 julia 300 | ||
>>> df2 = pd.DataFrame({'tool': ['python', 'r', 'julia'], | ||
... 'score': [300, 200, 100]}, | ||
... columns=['tool', 'score']) | ||
company cost revenue | ||
0 A 250 100 | ||
1 B 150 250 | ||
2 C 100 300 | ||
>>> df2 = pd.DataFrame({'company': ['A', 'B', 'C', 'D'], | ||
... 'revenue': [300, 250, 100, 150]}) | ||
>>> df2 | ||
tool score | ||
0 python 300 | ||
1 r 200 | ||
2 julia 100 | ||
company revenue | ||
0 A 300 | ||
1 B 250 | ||
2 C 100 | ||
3 D 150 | ||
>>> df1.ge(df2) | ||
tool score | ||
0 True False | ||
1 True True | ||
2 True True | ||
company cost revenue | ||
0 True False False | ||
1 True False True | ||
2 True False True | ||
3 False False False | ||
""" | ||
|
||
_comp_others = """ | ||
DataFrame.eq : Return DataFrame of boolean values equal to the | ||
elementwise rows or columns of one DataFrame to another | ||
DataFrame.ne : Return DataFrame of boolean values not equal to | ||
the elementwise rows or columns of one DataFrame to another | ||
DataFrame.le : Return DataFrame of boolean values less than or | ||
equal the elementwise rows or columns of one DataFrame | ||
to another | ||
DataFrame.lt : Return DataFrame of boolean values strictly less | ||
than the elementwise rows or columns of one DataFrame to | ||
another | ||
DataFrame.ge : Return DataFrame of boolean values greater than or | ||
equal to the elementwise rows or columns of one DataFrame to | ||
another | ||
DataFrame.gt : Return DataFrame of boolean values strictly greater | ||
than to the elementwise rows or columns of one DataFrame to | ||
another | ||
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 | ||
""" | ||
|
||
_op_descriptions = { | ||
|
@@ -598,17 +598,17 @@ def _get_op_name(op, special): | |
# Comparison Operators | ||
'eq': {'op': '==', | ||
'desc': 'Equal to', | ||
'reverse': 'ne', | ||
'reverse': None, | ||
'df_examples': _eq_example_FRAME, | ||
'others': _comp_others}, | ||
'ne': {'op': '!=', | ||
'desc': 'Not equal to', | ||
'reverse': 'eq', | ||
'reverse': None, | ||
'df_examples': _ne_example_FRAME, | ||
'others': _comp_others}, | ||
'lt': {'op': '<', | ||
'desc': 'Less than', | ||
'reverse': 'ge', | ||
'reverse': None, | ||
'df_examples': _lt_example_FRAME, | ||
'others': _comp_others}, | ||
'le': {'op': '<=', | ||
|
@@ -618,12 +618,12 @@ def _get_op_name(op, special): | |
'others': _comp_others}, | ||
'gt': {'op': '>', | ||
'desc': 'Greater than', | ||
'reverse': 'le', | ||
'reverse': None, | ||
'df_examples': _gt_example_FRAME, | ||
'others': _comp_others}, | ||
'ge': {'op': '>=', | ||
'desc': 'Greater than or equal to', | ||
'reverse': 'lt', | ||
'reverse': None, | ||
'df_examples': _ge_example_FRAME, | ||
'others': _comp_others}} | ||
|
||
|
@@ -754,30 +754,36 @@ def _get_op_name(op, special): | |
_flex_comp_doc_FRAME = """ | ||
Flexible wrappers to comparison operators (specifically ``{name}``). | ||
|
||
Wrappers (``eq``, ``ne``, ``le``, ``lt``, ``ge``, ``gt``) are equivalent to | ||
operators (``==``, ``=!``, ``<=``, ``<``, ``>=``, ``>``) with support to choose | ||
Equivalent to `==`, `=!`, `<=`, `<`, `>=`, `>` with support to choose | ||
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'm a bit confused... In the previous dictionaries, you define 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. To be consistent with examples that run through several of these sibling methods, the intro lists all of them. It seems counterintuitive to have an intro that describes one method with examples from several methods. |
||
axis (rows or columns) for comparison. | ||
|
||
Parameters | ||
---------- | ||
other : DataFrame | ||
axis : {{0, 1, 'columns', 'rows'}} | ||
Any structured DataFrame. Can be different number of columns or rows. | ||
axis : int or str, optional | ||
Axis to target. Can be either the axis name ('index', 'rows', | ||
'columns') or number (0, 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. To be consistent, I'd document the axis as we usually do. See this docstring: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html |
||
level : int or name | ||
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. Better to use 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. Will do. |
||
Broadcast across a level, matching Index values on the | ||
passed MultiIndex level | ||
Broadcast across a level, matching Index values on the passed | ||
MultiIndex level. | ||
|
||
Returns | ||
------- | ||
result : DataFrame | ||
Consisting of boolean values | ||
|
||
Examples | ||
-------- | ||
{df_examples} | ||
result : DataFrame of bool | ||
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. We don't need 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. Will do. |
||
Result of the comparison. | ||
|
||
See also | ||
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 the 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 see no current docs page that has |
||
-------- | ||
{reverse} | ||
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 run 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. You are right. And strangely errors did not mention the order of See Also (possibly capitalization of A was the issue?). 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. We still need to add several validations to that script. The order of the sections is one of them. |
||
|
||
Notes | ||
-------- | ||
Mismatched indices will be unioned together. | ||
datapythonista marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Examples | ||
-------- | ||
{df_examples} | ||
""" | ||
|
||
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. 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? 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 = """ | ||
|
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'm not sure if I'm missing something, but is this always the same for all methods? It could go directly to the doctring and not in a separate variable if that's the case. Besides good docstrings, it's good if we keep the code as simple as possible. So we usually leave the same
See Also
for all methods in this case, even if the method being documented is self referencing.Also, do you think we can find something less verbose for the descriptions. Something like
Compare DataFrames for equality elementwise
may be?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.
Though much of the words are the same, they differ slightly in the middle. Are you advising removing descriptions?
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.
No, what I meant is that if it's possible, it'd be good that each of these descriptions is shorter. Just making them more concise if you find the way.