-
-
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 1 commit
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 |
---|---|---|
|
@@ -502,6 +502,20 @@ def no_punctuation(self): | |
return "Hello world!" | ||
|
||
|
||
class BadExamples(object): | ||
|
||
def npPd_import(self): | ||
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 name is a bit cryptic, can you use something more clear. |
||
""" | ||
Provide example with numpy and pandas import | ||
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 finish this with a period, so it doesn't generate an error for it. |
||
|
||
Examples | ||
-------- | ||
import numpy as np | ||
import pandas as pd | ||
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. The code in examples start by It'd be good to have tests for Not sure if in the good docstrings in the tests we have examples somewhere. We should, to make sure the error is not reported when |
||
""" | ||
pass | ||
|
||
|
||
class TestValidator(object): | ||
|
||
def _import_path(self, klass=None, func=None): | ||
|
@@ -600,7 +614,11 @@ def test_bad_generic_functions(self, func): | |
pytest.param('BadReturns', 'no_description', ('foo',), | ||
marks=pytest.mark.xfail), | ||
pytest.param('BadReturns', 'no_punctuation', ('foo',), | ||
marks=pytest.mark.xfail) | ||
marks=pytest.mark.xfail), | ||
# Examples | ||
('BadExamples', 'npPd_import', | ||
('Examples should not have `import pandas as pd` ', | ||
'Examples should not have `import numpy as np` ',)) | ||
]) | ||
def test_bad_examples(self, capsys, klass, func, msgs): | ||
result = validate_one(self._import_path(klass=klass, func=func)) # noqa:F821 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,6 +512,12 @@ def validate_one(func_name): | |
examples_errs = doc.examples_errors | ||
if examples_errs: | ||
errs.append('Examples do not pass tests') | ||
if 'import numpy as np' in ' '.join(doc.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 it'd be good to use the module
should not generate an error. And probably you want to include an example like this in the tests. |
||
errs.append(' Examples should not have ' | ||
'`import numpy as np` ') | ||
if 'import pandas as pd' in ' '.join(doc.examples): | ||
errs.append(' Examples should not have ' | ||
'`import pandas 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.
I believe there is already an example that imports both of these:
pandas/scripts/tests/test_validate_docstrings.py
Line 334 in 5aff727
Any reason we don't leverage that instead of creating a new class?