Skip to content

Commit 83d4dfd

Browse files
seth-pjorisvandenbossche
authored andcommitted
ENH: Added api_rst_coverage.py (pandas-dev#8166)
1 parent c74820e commit 83d4dfd

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

doc/source/contributing.rst

+7
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ Some other important things to know about the docs:
316316
output saved) during the doc build. This way, they will always be up to date,
317317
but it makes the doc building a bit more complex.
318318

319+
The utility script ``scripts/api_rst_coverage.py`` can be used to compare
320+
the list of methods documented in ``doc/source/api.rst`` (which is used to generate
321+
the `API Reference <http://pandas.pydata.org/pandas-docs/stable/api.html>`_ page)
322+
and the actual public methods.
323+
It will identify methods documented in in ``doc/source/api.rst`` that are not actually
324+
class methods, and existing methods that are not documented in ``doc/source/api.rst``.
325+
319326

320327
How to build the pandas documentation
321328
-------------------------------------

scripts/api_rst_coverage.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pandas as pd
2+
import inspect
3+
import re
4+
5+
def main():
6+
# classes whose members to check
7+
classes = [pd.Series, pd.DataFrame, pd.Panel, pd.Panel4D]
8+
9+
def class_name_sort_key(x):
10+
if x.startswith('Series'):
11+
# make sure Series precedes DataFrame, Panel, and Panel4D
12+
return ' ' + x
13+
else:
14+
return x
15+
16+
# class members
17+
class_members = set()
18+
for cls in classes:
19+
class_members.update([cls.__name__ + '.' + x[0] for x in inspect.getmembers(cls)])
20+
21+
# class members referenced in api.rst
22+
api_rst_members = set()
23+
file_name = '../doc/source/api.rst'
24+
with open(file_name, 'r') as f:
25+
pattern = re.compile('({})\.(\w+)'.format('|'.join([cls.__name__ for cls in classes])))
26+
for line in f:
27+
match = pattern.search(line)
28+
if match:
29+
api_rst_members.add(match.group(0))
30+
31+
print()
32+
print("Documented members in api.rst that aren't actual class members:")
33+
for x in sorted(api_rst_members.difference(class_members), key=class_name_sort_key):
34+
print(x)
35+
36+
print()
37+
print("Class members (other than those beginning with '_') missing from api.rst:")
38+
for x in sorted(class_members.difference(api_rst_members), key=class_name_sort_key):
39+
if '._' not in x:
40+
print(x)
41+
42+
if __name__ == "__main__":
43+
main()

0 commit comments

Comments
 (0)