Skip to content

Commit 8655fdd

Browse files
committed
Check numpy and pandas in Examples
1 parent cf11f71 commit 8655fdd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

scripts/tests/test_validate_docstrings.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,20 @@ def no_punctuation(self):
502502
return "Hello world!"
503503

504504

505+
class BadExamples(object):
506+
507+
def npPd_import(self):
508+
"""
509+
Provide example with numpy and pandas import
510+
511+
Examples
512+
--------
513+
import numpy as np
514+
import pandas as pd
515+
"""
516+
pass
517+
518+
505519
class TestValidator(object):
506520

507521
def _import_path(self, klass=None, func=None):
@@ -600,7 +614,11 @@ def test_bad_generic_functions(self, func):
600614
pytest.param('BadReturns', 'no_description', ('foo',),
601615
marks=pytest.mark.xfail),
602616
pytest.param('BadReturns', 'no_punctuation', ('foo',),
603-
marks=pytest.mark.xfail)
617+
marks=pytest.mark.xfail),
618+
# Examples
619+
('BadExamples', 'npPd_import',
620+
('Examples should not have `import pandas as pd` ',
621+
'Examples should not have `import numpy as np` ',))
604622
])
605623
def test_bad_examples(self, capsys, klass, func, msgs):
606624
result = validate_one(self._import_path(klass=klass, func=func)) # noqa:F821

scripts/validate_docstrings.py

+6
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,12 @@ def validate_one(func_name):
512512
examples_errs = doc.examples_errors
513513
if examples_errs:
514514
errs.append('Examples do not pass tests')
515+
if 'import numpy as np' in ' '.join(doc.examples):
516+
errs.append(' Examples should not have '
517+
'`import numpy as np` ')
518+
if 'import pandas as pd' in ' '.join(doc.examples):
519+
errs.append(' Examples should not have '
520+
'`import pandas as pd` ')
515521

516522
return {'type': doc.type,
517523
'docstring': doc.clean_doc,

0 commit comments

Comments
 (0)