-
-
Notifications
You must be signed in to change notification settings - Fork 18.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 6 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 |
---|---|---|
|
@@ -397,6 +397,66 @@ def _get_op_name(op, special): | |
e NaN -2.0 | ||
""" | ||
|
||
_gt_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'num1': range(1,6), | ||
... 'num2': range(2,11,2), | ||
... 'num3': range(1,20,4)}) | ||
>>> df1 | ||
num1 num2 num3 | ||
0 1 2 1 | ||
1 2 4 5 | ||
2 3 6 9 | ||
3 4 8 13 | ||
4 5 10 17 | ||
>>> df2 = pd.DataFrame({'num1': range(6,11), | ||
... 'num2': range(1,10,2), | ||
... 'num3': range(1,20,4)}) | ||
>>> df2 | ||
num1 num2 num3 | ||
0 6 1 1 | ||
1 7 3 5 | ||
2 8 5 9 | ||
3 9 7 13 | ||
4 10 9 17 | ||
>>> df1.gt(df2) | ||
num1 num2 num3 | ||
0 False True False | ||
1 False True False | ||
2 False True False | ||
3 False True False | ||
4 False True False | ||
""" | ||
|
||
_ge_example_FRAME = """ | ||
>>> df1 = pd.DataFrame({'num1': range(1,6), | ||
... 'num2': range(2,11,2), | ||
... 'num3': range(1,20,4)}) | ||
>>> df1 | ||
num1 num2 num3 | ||
0 1 2 1 | ||
1 2 4 5 | ||
2 3 6 9 | ||
3 4 8 13 | ||
4 5 10 17 | ||
>>> df2 = pd.DataFrame({'num1': range(6,11), | ||
... 'num2': range(1,10,2), | ||
... 'num3': range(1,20,4)}) | ||
>>> df2 | ||
num1 num2 num3 | ||
0 6 1 1 | ||
1 7 3 5 | ||
2 8 5 9 | ||
3 9 7 13 | ||
4 10 9 17 | ||
>>> df1.ge(df2) | ||
num1 num2 num3 | ||
0 False True True | ||
1 False True True | ||
2 False True True | ||
3 False True True | ||
4 False True 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. 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 Also, do you think we can find something less verbose for the descriptions. Something like 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. 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 commentThe 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. |
||
|
||
_op_descriptions = { | ||
# Arithmetic Operators | ||
'add': {'op': '+', | ||
|
@@ -452,11 +512,11 @@ def _get_op_name(op, special): | |
'gt': {'op': '>', | ||
'desc': 'Greater than', | ||
'reverse': None, | ||
'df_examples': None}, | ||
'df_examples': _gt_example_FRAME}, | ||
'ge': {'op': '>=', | ||
'desc': 'Greater than or equal to', | ||
'reverse': None, | ||
'df_examples': None}} | ||
'df_examples': _ge_example_FRAME}} | ||
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. Any reason why you chose these two? 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. This was part of the Pandas Doc Sprint some months ago. I was tasked with ge/gt functions with teammates handling others. But we can incorporate le/lt and eq/ne pairs with similar set of examples. |
||
|
||
_op_names = list(_op_descriptions.keys()) | ||
for key in _op_names: | ||
|
@@ -582,6 +642,14 @@ def _get_op_name(op, special): | |
DataFrame.{reverse} | ||
""" | ||
|
||
_flex_comp_doc_FRAME = """ | ||
Wrapper for flexible comparison methods {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. This could use a description of what “flexible” means in this context. 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 maintained original text and only added examples. Please advise on text changes. |
||
|
||
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 = """ | ||
{desc} of series and other, element-wise (binary operator `{op_name}`). | ||
Equivalent to ``{equiv}``. | ||
|
@@ -1546,8 +1614,18 @@ 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)) | ||
doc = ('Wrapper for flexible comparison methods {name}' | ||
.format(name=op_name)) | ||
|
||
if op_name in _op_descriptions: | ||
op_desc = _op_descriptions[op_name] | ||
|
||
if op_desc['df_examples'] is not None: | ||
base_doc = _flex_comp_doc_FRAME | ||
doc = base_doc.format(name=op_name, | ||
df_examples=op_desc['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. Pls add a |
||
|
||
@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) | ||
|
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.
In case the doc linter cares,about it, add spaces after commas here
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.
Pls add a space after each of the commas in the
range
calls.