Skip to content

ENH: added api_rst_coverage.py #8166

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ Some other important things to know about the docs:
output saved) during the doc build. This way, they will always be up to date,
but it makes the doc building a bit more complex.

- The utility script ``scripts/api_rst_coverage.py`` can be used to compare
the list of methods documented in ``doc/source/api.rst`` (which is used to generate
the `API Reference <http://pandas.pydata.org/pandas-docs/version/0.16.0/api.html>`_ page)
and the actual methods of the classes ``Series``, ``DataFrame``, ``Panel``, and ``Panel4D``.
It will identify methods documented in in ``doc/source/api.rst`` that are not actually
class methods, and class methods that are not documented in ``doc/source/api.rst``.
Copy link
Contributor

Choose a reason for hiding this comment

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

didn't nice this but should point to latest

Copy link
Member

Choose a reason for hiding this comment

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

yep, I changed that in what I actually committed



How to build the pandas documentation
-------------------------------------
Expand Down
43 changes: 43 additions & 0 deletions scripts/api_rst_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pandas as pd
import inspect
import re

def main():
# classes whose members to check
classes = [pd.Series, pd.DataFrame, pd.Panel, pd.Panel4D]

def class_name_sort_key(x):
if x.startswith('Series'):
# make sure Series precedes DataFrame, Panel, and Panel4D
return ' ' + x
else:
return x

# class members
class_members = set()
for cls in classes:
class_members.update([cls.__name__ + '.' + x[0] for x in inspect.getmembers(cls)])

# class members referenced in api.rst
api_rst_members = set()
file_name = '../doc/source/api.rst'
with open(file_name, 'r') as f:
pattern = re.compile('({})\.(\w+)'.format('|'.join([cls.__name__ for cls in classes])))
for line in f:
match = pattern.search(line)
if match:
api_rst_members.add(match.group(0))

print()
print("Documented members in api.rst that aren't actual class members:")
for x in sorted(api_rst_members.difference(class_members), key=class_name_sort_key):
print(x)

print()
print("Class members (other than those beginning with '_') missing from api.rst:")
for x in sorted(class_members.difference(api_rst_members), key=class_name_sort_key):
if '._' not in x:
print(x)

if __name__ == "__main__":
main()