Skip to content

Commit 561f3c3

Browse files
committed
[skip ci] Minor changes
Signed-off-by: Fabian Haase <[email protected]>
1 parent affd8f4 commit 561f3c3

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

scripts/tests/test_validate_docstrings.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -584,24 +584,15 @@ def prefix_pandas(self):
584584

585585
class BadExamples(object):
586586

587-
def numpy_imported(self):
587+
def unused_import(self):
588588
"""
589589
Examples
590590
--------
591-
>>> import numpy as np
591+
>>> import pandas as pdf
592592
>>> df = pd.DataFrame(np.ones((3, 3)), columns=('a', 'b', 'c'))
593593
"""
594594
pass
595595

596-
def pandas_imported(self):
597-
"""
598-
Examples
599-
--------
600-
>>> import pandas as pd
601-
>>> s = pd.Series(['Antelope', 'Lion', 'Zebra', np.nan])
602-
"""
603-
pass
604-
605596
def missing_whitespace_around_arithmetic_operator(self):
606597
"""
607598
Examples
@@ -750,16 +741,12 @@ def test_bad_generic_functions(self, func):
750741
('pandas.Series.rename in `See Also` section '
751742
'does not need `pandas` prefix',)),
752743
# Examples tests
753-
('BadExamples', 'numpy_imported',
754-
('F811 It\'s assumed that pandas and numpy'
755-
' are imported as pd or np',)),
756-
('BadExamples', 'pandas_imported',
757-
('F811 It\'s assumed that pandas and numpy'
758-
' are imported as pd or np',)),
744+
('BadExamples', 'unused_import',
745+
('1 F401 \'pandas as pdf\' imported but unused',)),
759746
('BadExamples', 'indentation_is_not_a_multiple_of_four',
760-
('E111 indentation is not a multiple of four',)),
747+
('1 E111 indentation is not a multiple of four',)),
761748
('BadExamples', 'missing_whitespace_around_arithmetic_operator',
762-
('E226 missing whitespace around arithmetic operator',)),
749+
('1 E226 missing whitespace around arithmetic operator',)),
763750
('BadExamples', 'missing_whitespace_after_comma',
764751
('3 E231 missing whitespace after \',\'',)),
765752
])

scripts/validate_docstrings.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
$ ./validate_docstrings.py
1414
$ ./validate_docstrings.py pandas.DataFrame.head
1515
"""
16-
import contextlib
1716
import os
1817
import sys
1918
import json
@@ -173,7 +172,7 @@ def _load_obj(name):
173172
@staticmethod
174173
def _to_original_callable(obj):
175174
"""
176-
Find the Python object that contains the source code ot the object.
175+
Find the Python object that contains the source code of the object.
177176
178177
This is useful to find the place in the source code (file and line
179178
number) where a docstring is defined. It does not currently work for
@@ -336,32 +335,25 @@ def parameter_mismatches(self):
336335

337336
return errs
338337

339-
@contextlib.contextmanager
340-
def _write_examples_code_to_temp_file(self):
341-
"""
342-
Generate file with source code from examples section.
343-
"""
344-
content = ''.join(('import numpy as np; '
345-
'import pandas as pd # noqa: F401,E702\n',
338+
def validate_pep8(self):
339+
if not self.examples:
340+
return
341+
342+
content = ''.join(('import numpy as np # noqa: F401\n',
343+
'import pandas as pd # noqa: F401\n',
346344
*self.examples_source_code))
345+
346+
application = flake8.main.application.Application()
347+
application.initialize(["--quiet"])
348+
347349
with tempfile.NamedTemporaryFile(mode='w') as file:
348350
file.write(content)
349351
file.flush()
350-
yield file
352+
application.run_checks([file.name])
351353

352-
def validate_pep8(self):
353-
if self.examples:
354-
with self._write_examples_code_to_temp_file() as file:
355-
application = flake8.main.application.Application()
356-
application.initialize(["--quiet"])
357-
application.run_checks([file.name])
358-
application.report()
359-
360-
for statistic in application.guide.stats.statistics_for(''):
361-
if statistic.message.endswith('from line 1'):
362-
statistic.message = "It's assumed that pandas and numpy" \
363-
" are imported as pd or np"
364-
yield statistic
354+
application.report()
355+
356+
yield from application.guide.stats.statistics_for('')
365357

366358
@property
367359
def correct_parameters(self):

0 commit comments

Comments
 (0)