Skip to content

Commit 762de5d

Browse files
committed
Fixed failing tests.
* Examples in `test_validate_docstrings.py` lacked imports * Removed signature from function in generated file as not really needed at this point. * Used `clean_doc` instead of `raw_doc` to get correct indentation. * Added missing try: finally: block in `_file_representation()` Signed-off-by: Fabian Haase <[email protected]>
1 parent cb477f8 commit 762de5d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

scripts/tests/test_validate_docstrings.py

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def contains(self, pat, case=True, na=np.nan):
166166
Examples
167167
--------
168168
>>> import pandas as pd
169+
>>> import numpy as np
169170
>>> s = pd.Series(['Antelope', 'Lion', 'Zebra', np.nan])
170171
>>> s.str.contains(pat='a')
171172
0 False

scripts/validate_docstrings.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,12 @@ def pep8_violations(self):
344344
@contextmanager
345345
def _file_representation(self):
346346
"""
347-
Creates a tmp file containing the function without the body
347+
Temporarily creates file with current function inside.
348+
The signature and body are **not** included.
348349
349350
:returns filename of tmp file
350351
"""
351-
create_function = 'def {name}{signature}: # noqa: E501\n' \
352+
create_function = 'def {name}():\n' \
352353
' """{doc}"""\n' \
353354
' pass\n'
354355

@@ -358,18 +359,17 @@ def _file_representation(self):
358359
filename = os.path.join(tmp_dir, self.name + '.py')
359360
with open(filename, 'w') as f:
360361
name = self.name.split('.')[-1]
361-
sig = str(inspect.signature(self.obj))
362-
lines = self.raw_doc.split("\n")
363-
indented_lines = [' ' + line if line else ''
362+
lines = self.clean_doc.split("\n")
363+
indented_lines = [(' ' * 4) + line if line else ''
364364
for line in lines[1:]]
365365
doc = '\n'.join([lines[0], *indented_lines])
366366

367-
f.write(create_function.format(name=name, signature=sig, doc=doc))
368-
369-
yield filename
370-
371-
os.remove(filename)
372-
os.rmdir(tmp_dir)
367+
f.write(create_function.format(name=name, doc=doc))
368+
try:
369+
yield filename
370+
finally:
371+
os.remove(filename)
372+
os.rmdir(tmp_dir)
373373

374374
@property
375375
def correct_parameters(self):

setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ exclude_from_doctest =
4242
./pandas/io
4343
./pandas/plotting
4444
./pandas/tests
45-
./pandas/tools
4645
./pandas/tseries
4746
./pandas/util
4847

0 commit comments

Comments
 (0)