Skip to content

Commit 19ec625

Browse files
committed
Revert "Remove unnecessary templates"
This reverts commit 80b6bf9.
1 parent 232d86f commit 19ec625

File tree

7 files changed

+93
-12
lines changed

7 files changed

+93
-12
lines changed

doc/source/conf.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,45 @@ def remove_flags_docstring(app, what, name, obj, options, lines):
696696
del lines[:]
697697

698698

699+
def process_class_docstrings(app, what, name, obj, options, lines):
700+
"""
701+
For those classes for which we use ::
702+
703+
:template: autosummary/class_without_autosummary.rst
704+
705+
the documented attributes/methods have to be listed in the class
706+
docstring. However, if one of those lists is empty, we use 'None',
707+
which then generates warnings in sphinx / ugly html output.
708+
This "autodoc-process-docstring" event connector removes that part
709+
from the processed docstring.
710+
711+
"""
712+
if what == "class":
713+
joined = "\n".join(lines)
714+
715+
templates = [
716+
""".. rubric:: Attributes
717+
718+
.. autosummary::
719+
:toctree:
720+
721+
None
722+
""",
723+
""".. rubric:: Methods
724+
725+
.. autosummary::
726+
:toctree:
727+
728+
None
729+
""",
730+
]
731+
732+
for template in templates:
733+
if template in joined:
734+
joined = joined.replace(template, "")
735+
lines[:] = joined.split("\n")
736+
737+
699738
_BUSINED_ALIASES = [
700739
"pandas.tseries.offsets." + name
701740
for name in [
@@ -748,6 +787,7 @@ def rstjinja(app, docname, source):
748787
def setup(app):
749788
app.connect("source-read", rstjinja)
750789
app.connect("autodoc-process-docstring", remove_flags_docstring)
790+
app.connect("autodoc-process-docstring", process_class_docstrings)
751791
app.connect("autodoc-process-docstring", process_business_alias_docstrings)
752792
app.add_autodocumenter(AccessorDocumenter)
753793
app.add_autodocumenter(AccessorAttributeDocumenter)

doc/source/development/contributing_documentation.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,25 @@ Some other important things to know about the docs:
7373

7474
* Our API documentation files in ``doc/source/reference`` house the auto-generated
7575
documentation from the docstrings. For classes, there are a few subtleties
76-
around controlling which methods and attributes have pages auto-generated. The
77-
default autosummary template will generate pages for all public methods and
78-
attributes of classes. ``numpydoc`` will also automatically generate an
79-
``Attributes`` and ``Methods`` section for the class, leading to a redundant
80-
specification. To prevent this duplication, we have a custom autosummary
81-
template ``_templates/autosummary/class.rst`` that will generate class pages
82-
without any method or attribute documentation.
83-
84-
For some classes we only want to document a subset of APIs. For those, the
85-
you should include an ``Attributes`` and ``Methods`` section in the class
86-
docstring. See ``CategoricalIndex`` for an example.
76+
around controlling which methods and attributes have pages auto-generated.
77+
78+
We have two autosummary templates for classes.
79+
80+
1. ``_templates/autosummary/class.rst``. Use this when you want to
81+
automatically generate a page for every public method and attribute on the
82+
class. The ``Attributes`` and ``Methods`` sections will be automatically
83+
added to the class' rendered documentation by numpydoc. See ``DataFrame``
84+
for an example.
85+
86+
2. ``_templates/autosummary/class_without_autosummary``. Use this when you
87+
want to pick a subset of methods / attributes to auto-generate pages for.
88+
When using this template, you should include an ``Attributes`` and
89+
``Methods`` section in the class docstring. See ``CategoricalIndex`` for an
90+
example.
8791

8892
Every method should be included in a ``toctree`` in one of the documentation files in
89-
``doc/source/reference``, otherwise Sphinx will emit a warning.
93+
``doc/source/reference``, else Sphinx
94+
will emit a warning.
9095

9196
The utility script ``scripts/validate_docstrings.py`` can be used to get a csv
9297
summary of the API documentation. And also validate common errors in the docstring

doc/source/reference/arrays.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ values.
104104

105105
.. autosummary::
106106
:toctree: api/
107+
:template: autosummary/class_without_autosummary.rst
107108

108109
arrays.ArrowExtensionArray
109110

110111
.. autosummary::
111112
:toctree: api/
113+
:template: autosummary/class_without_autosummary.rst
112114

113115
ArrowDtype
114116

@@ -231,11 +233,13 @@ If the data are timezone-aware, then every value in the array must have the same
231233

232234
.. autosummary::
233235
:toctree: api/
236+
:template: autosummary/class_without_autosummary.rst
234237

235238
arrays.DatetimeArray
236239

237240
.. autosummary::
238241
:toctree: api/
242+
:template: autosummary/class_without_autosummary.rst
239243

240244
DatetimeTZDtype
241245

@@ -295,6 +299,7 @@ A collection of :class:`Timedelta` may be stored in a :class:`TimedeltaArray`.
295299

296300
.. autosummary::
297301
:toctree: api/
302+
:template: autosummary/class_without_autosummary.rst
298303

299304
arrays.TimedeltaArray
300305

@@ -356,11 +361,13 @@ Every period in a :class:`arrays.PeriodArray` must have the same ``freq``.
356361

357362
.. autosummary::
358363
:toctree: api/
364+
:template: autosummary/class_without_autosummary.rst
359365

360366
arrays.PeriodArray
361367

362368
.. autosummary::
363369
:toctree: api/
370+
:template: autosummary/class_without_autosummary.rst
364371

365372
PeriodDtype
366373

@@ -397,11 +404,13 @@ A collection of intervals may be stored in an :class:`arrays.IntervalArray`.
397404

398405
.. autosummary::
399406
:toctree: api/
407+
:template: autosummary/class_without_autosummary.rst
400408

401409
arrays.IntervalArray
402410

403411
.. autosummary::
404412
:toctree: api/
413+
:template: autosummary/class_without_autosummary.rst
405414

406415
IntervalDtype
407416

@@ -440,11 +449,13 @@ pandas provides this through :class:`arrays.IntegerArray`.
440449

441450
.. autosummary::
442451
:toctree: api/
452+
:template: autosummary/class_without_autosummary.rst
443453

444454
arrays.IntegerArray
445455

446456
.. autosummary::
447457
:toctree: api/
458+
:template: autosummary/class_without_autosummary.rst
448459

449460
Int8Dtype
450461
Int16Dtype
@@ -463,11 +474,13 @@ Nullable float
463474

464475
.. autosummary::
465476
:toctree: api/
477+
:template: autosummary/class_without_autosummary.rst
466478

467479
arrays.FloatingArray
468480

469481
.. autosummary::
470482
:toctree: api/
483+
:template: autosummary/class_without_autosummary.rst
471484

472485
Float32Dtype
473486
Float64Dtype
@@ -484,6 +497,7 @@ a :class:`CategoricalDtype`.
484497

485498
.. autosummary::
486499
:toctree: api/
500+
:template: autosummary/class_without_autosummary.rst
487501

488502
CategoricalDtype
489503

@@ -497,6 +511,7 @@ Categorical data can be stored in a :class:`pandas.Categorical`
497511

498512
.. autosummary::
499513
:toctree: api/
514+
:template: autosummary/class_without_autosummary.rst
500515

501516
Categorical
502517

@@ -546,11 +561,13 @@ be stored efficiently as a :class:`arrays.SparseArray`.
546561

547562
.. autosummary::
548563
:toctree: api/
564+
:template: autosummary/class_without_autosummary.rst
549565

550566
arrays.SparseArray
551567

552568
.. autosummary::
553569
:toctree: api/
570+
:template: autosummary/class_without_autosummary.rst
554571

555572
SparseDtype
556573

@@ -569,12 +586,14 @@ we recommend using :class:`StringDtype` (with the alias ``"string"``).
569586

570587
.. autosummary::
571588
:toctree: api/
589+
:template: autosummary/class_without_autosummary.rst
572590

573591
arrays.StringArray
574592
arrays.ArrowStringArray
575593

576594
.. autosummary::
577595
:toctree: api/
596+
:template: autosummary/class_without_autosummary.rst
578597

579598
StringDtype
580599

@@ -593,11 +612,13 @@ with a bool :class:`numpy.ndarray`.
593612

594613
.. autosummary::
595614
:toctree: api/
615+
:template: autosummary/class_without_autosummary.rst
596616

597617
arrays.BooleanArray
598618

599619
.. autosummary::
600620
:toctree: api/
621+
:template: autosummary/class_without_autosummary.rst
601622

602623
BooleanDtype
603624
NA

doc/source/reference/extensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ objects.
2121

2222
.. autosummary::
2323
:toctree: api/
24+
:template: autosummary/class_without_autosummary.rst
2425

2526
api.extensions.ExtensionArray
2627
arrays.NumpyExtensionArray

doc/source/reference/groupby.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Indexing, iteration
2929

3030
.. autosummary::
3131
:toctree: api/
32+
:template: autosummary/class_without_autosummary.rst
3233

3334
Grouper
3435

doc/source/reference/indexing.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Numeric Index
163163
-------------
164164
.. autosummary::
165165
:toctree: api/
166+
:template: autosummary/class_without_autosummary.rst
166167

167168
RangeIndex
168169

@@ -183,6 +184,7 @@ CategoricalIndex
183184
----------------
184185
.. autosummary::
185186
:toctree: api/
187+
:template: autosummary/class_without_autosummary.rst
186188

187189
CategoricalIndex
188190

@@ -217,6 +219,7 @@ IntervalIndex
217219
-------------
218220
.. autosummary::
219221
:toctree: api/
222+
:template: autosummary/class_without_autosummary.rst
220223

221224
IntervalIndex
222225

@@ -251,6 +254,7 @@ MultiIndex
251254

252255
.. autosummary::
253256
:toctree: api/
257+
:template: autosummary/class_without_autosummary.rst
254258

255259
MultiIndex
256260

@@ -317,6 +321,7 @@ DatetimeIndex
317321
-------------
318322
.. autosummary::
319323
:toctree: api/
324+
:template: autosummary/class_without_autosummary.rst
320325

321326
DatetimeIndex
322327

@@ -402,6 +407,7 @@ TimedeltaIndex
402407
--------------
403408
.. autosummary::
404409
:toctree: api/
410+
:template: autosummary/class_without_autosummary.rst
405411

406412
TimedeltaIndex
407413

@@ -443,6 +449,7 @@ PeriodIndex
443449
-----------
444450
.. autosummary::
445451
:toctree: api/
452+
:template: autosummary/class_without_autosummary.rst
446453

447454
PeriodIndex
448455

doc/source/reference/offset_frequency.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Alias:
5656

5757
.. autosummary::
5858
:toctree: api/
59+
:template: autosummary/class_without_autosummary.rst
5960

6061
BDay
6162

@@ -142,6 +143,7 @@ Alias:
142143

143144
.. autosummary::
144145
:toctree: api/
146+
:template: autosummary/class_without_autosummary.rst
145147

146148
CDay
147149

@@ -298,6 +300,7 @@ Alias:
298300

299301
.. autosummary::
300302
:toctree: api/
303+
:template: autosummary/class_without_autosummary.rst
301304

302305
BMonthEnd
303306

@@ -341,6 +344,7 @@ Alias:
341344

342345
.. autosummary::
343346
:toctree: api/
347+
:template: autosummary/class_without_autosummary.rst
344348

345349
BMonthBegin
346350

@@ -384,6 +388,7 @@ Alias:
384388

385389
.. autosummary::
386390
:toctree: api/
391+
:template: autosummary/class_without_autosummary.rst
387392

388393
CBMonthEnd
389394

@@ -431,6 +436,7 @@ Alias:
431436

432437
.. autosummary::
433438
:toctree: api/
439+
:template: autosummary/class_without_autosummary.rst
434440

435441
CBMonthBegin
436442

0 commit comments

Comments
 (0)