Skip to content

Commit c5a1ef1

Browse files
DOC: remove empty attribute/method lists from class docstrings html page (#19949)
1 parent 9958ce6 commit c5a1ef1

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

doc/source/conf.py

+40
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,45 @@ def remove_flags_docstring(app, what, name, obj, options, lines):
552552
del lines[:]
553553

554554

555+
def process_class_docstrings(app, what, name, obj, options, lines):
556+
"""
557+
For those classes for which we use ::
558+
559+
:template: autosummary/class_without_autosummary.rst
560+
561+
the documented attributes/methods have to be listed in the class
562+
docstring. However, if one of those lists is empty, we use 'None',
563+
which then generates warnings in sphinx / ugly html output.
564+
This "autodoc-process-docstring" event connector removes that part
565+
from the processed docstring.
566+
567+
"""
568+
if what == "class":
569+
joined = '\n'.join(lines)
570+
571+
templates = [
572+
""".. rubric:: Attributes
573+
574+
.. autosummary::
575+
:toctree:
576+
577+
None
578+
""",
579+
""".. rubric:: Methods
580+
581+
.. autosummary::
582+
:toctree:
583+
584+
None
585+
"""
586+
]
587+
588+
for template in templates:
589+
if template in joined:
590+
joined = joined.replace(template, '')
591+
lines[:] = joined.split('\n')
592+
593+
555594
suppress_warnings = [
556595
# We "overwrite" autosummary with our PandasAutosummary, but
557596
# still want the regular autosummary setup to run. So we just
@@ -562,6 +601,7 @@ def remove_flags_docstring(app, what, name, obj, options, lines):
562601

563602
def setup(app):
564603
app.connect("autodoc-process-docstring", remove_flags_docstring)
604+
app.connect("autodoc-process-docstring", process_class_docstrings)
565605
app.add_autodocumenter(AccessorDocumenter)
566606
app.add_autodocumenter(AccessorAttributeDocumenter)
567607
app.add_autodocumenter(AccessorMethodDocumenter)

pandas/core/indexes/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def is_all_dates(self):
131131
132132
Attributes
133133
----------
134-
inferred_type
134+
None
135135
136136
Methods
137137
-------

pandas/core/indexes/range.py

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class RangeIndex(Int64Index):
5353
Index : The base pandas Index type
5454
Int64Index : Index of int64 data
5555
56+
Attributes
57+
----------
58+
None
59+
5660
Methods
5761
-------
5862
from_range

0 commit comments

Comments
 (0)