Skip to content
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

DOC: remove empty attribute/method lists from class docstrings html page #19949

Merged
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
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