Skip to content

DOC: validate_docstrings cleans up leftover files; doctest +SKIP file examples #44711

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

Merged
merged 6 commits into from
Dec 2, 2021

Conversation

mroeschke
Copy link
Member

May help towards: #44590

@mroeschke mroeschke added the Docs label Dec 1, 2021
@mroeschke mroeschke added this to the 1.4 milestone Dec 2, 2021
for test in finder.find(self.raw_doc, self.name, globs=context):
f = io.StringIO()
runner.run(test, out=f.write)
error_msgs += f.getvalue()
leftovers = set(os.listdir()).difference(current_dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do this why do we need skips?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to validate that no doctest ever creates leftover files. So the workflow is

  1. Check if a docstring leftover a file/folder
  2. If so, clean up those leftover files
  3. Short-circut the validation and raise that a docstring leftover a file/folder

May helps potentially avoid any ResourceWarnings or potential segfaults from the docstring validation due to created files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i get it, but you added skips to all of the doc-strings hence they are not running?

Copy link
Member Author

@mroeschke mroeschke Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

IMO those docstrings that show an example with interacting with files should be skipped since they are more of a demonstration. The same behavior interacting with our file should be sufficient tested in the test suite.

Also I think it's better than having os.remove everywhere in the docstrings.

And we have this precedent in the docstrings already to skip the ones that interact with files:

>>> pd.read_excel('tmp.xlsx', index_col=0) # doctest: +SKIP

@jreback jreback merged commit 54e9988 into pandas-dev:master Dec 2, 2021
@mroeschke mroeschke deleted the docs/skip_file_creation branch December 2, 2021 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: scripts/validate_docstrings.py should clean up files created from docstrings
2 participants