-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Validate in docstrings that numpy and pandas are not imported #23161
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 9 commits
8655fdd
5c071ec
5aff727
374c9ea
881b011
d824414
5d785c3
3e512ac
a2011b2
0243b91
d123b5c
ec78655
ce37c8a
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 |
---|---|---|
|
@@ -402,6 +402,12 @@ def examples_errors(self): | |
error_msgs += f.getvalue() | ||
return error_msgs | ||
|
||
@property | ||
def examples_source_code(self): | ||
codes = doctest.DocTestParser().get_examples(self.raw_doc) | ||
codes = [line.source for line in codes] | ||
return codes | ||
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 can also return in the previous line. May be |
||
|
||
|
||
def validate_one(func_name): | ||
""" | ||
|
@@ -531,6 +537,13 @@ def validate_one(func_name): | |
examples_errs = doc.examples_errors | ||
if examples_errs: | ||
errs.append('Examples do not pass tests') | ||
examples_source_code = doc.examples_source_code | ||
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. may be you can do the join here, so doesn't need to be repeated? also, is the lines end with |
||
if 'import numpy' in ' '.join(examples_source_code): | ||
errs.append("Numpy does not need to be imported in the examples, " | ||
"as it's assumed to be already imported as np") | ||
if 'import pandas' in ' '.join(examples_source_code): | ||
errs.append("Pandas does not need to be imported in the 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 don't usually use capitalized pandas, even at the beginning of sentence. And in this case, as it's more the name of the module than the project, I'd use lower case also for numpy. |
||
"as it's assumed to be already imported as pd") | ||
|
||
return {'type': doc.type, | ||
'docstring': doc.clean_doc, | ||
|
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.