-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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 6 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_codes(self): | ||||||
codes = doctest.DocTestParser().get_examples(self.raw_doc) | ||||||
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.
Suggested change
|
||||||
codes = [line.source for line in codes] | ||||||
return ' '.join(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. Can you return a list with each line instead? We'll reuse this property to validate pep8 too, and returning a single string with all the code joined is not useful in that case. Also, at least to me |
||||||
|
||||||
|
||||||
def validate_one(func_name): | ||||||
""" | ||||||
|
@@ -531,6 +537,11 @@ def validate_one(func_name): | |||||
examples_errs = doc.examples_errors | ||||||
if examples_errs: | ||||||
errs.append('Examples do not pass tests') | ||||||
examples_codes = doc.examples_codes | ||||||
if 'import numpy' in examples_codes: | ||||||
errs.append('Examples should not have `import numpy` ') | ||||||
if 'import pandas' in examples_codes: | ||||||
errs.append('Examples should not have `import pandas` ') | ||||||
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 error could be more descriptive. |
||||||
|
||||||
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.