Skip to content

Commit

Permalink
DOC: remove empty attribute/method lists from class docstrings html p…
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Mar 1, 2018
1 parent 9958ce6 commit c5a1ef1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
40 changes: 40 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,45 @@ def remove_flags_docstring(app, what, name, obj, options, lines):
del lines[:]


def process_class_docstrings(app, what, name, obj, options, lines):
"""
For those classes for which we use ::
:template: autosummary/class_without_autosummary.rst
the documented attributes/methods have to be listed in the class
docstring. However, if one of those lists is empty, we use 'None',
which then generates warnings in sphinx / ugly html output.
This "autodoc-process-docstring" event connector removes that part
from the processed docstring.
"""
if what == "class":
joined = '\n'.join(lines)

templates = [
""".. rubric:: Attributes
.. autosummary::
:toctree:
None
""",
""".. rubric:: Methods
.. autosummary::
:toctree:
None
"""
]

for template in templates:
if template in joined:
joined = joined.replace(template, '')
lines[:] = joined.split('\n')


suppress_warnings = [
# We "overwrite" autosummary with our PandasAutosummary, but
# still want the regular autosummary setup to run. So we just
Expand All @@ -562,6 +601,7 @@ def remove_flags_docstring(app, what, name, obj, options, lines):

def setup(app):
app.connect("autodoc-process-docstring", remove_flags_docstring)
app.connect("autodoc-process-docstring", process_class_docstrings)
app.add_autodocumenter(AccessorDocumenter)
app.add_autodocumenter(AccessorAttributeDocumenter)
app.add_autodocumenter(AccessorMethodDocumenter)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def is_all_dates(self):
Attributes
----------
inferred_type
None
Methods
-------
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class RangeIndex(Int64Index):
Index : The base pandas Index type
Int64Index : Index of int64 data
Attributes
----------
None
Methods
-------
from_range
Expand Down

0 comments on commit c5a1ef1

Please sign in to comment.