Skip to content

Commit

Permalink
Clean up autosummary usage (#54457)
Browse files Browse the repository at this point in the history
* Disable numpydoc and use autosummary instead

* Add toctree for accessors
  • Loading branch information
vyasr authored Aug 18, 2023
1 parent d5a5a4d commit eb98a47
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
51 changes: 25 additions & 26 deletions doc/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
{% extends "!autosummary/class.rst" %}
{{ fullname | escape | underline}}

{% block methods %}
{% if methods %}
.. currentmodule:: {{ module }}

..
HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages.
.. autosummary::
:toctree:
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__'] %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
.. autoclass:: {{ objname }}

{% endif %}
{% endblock %}
{% block methods %}

{% block attributes %}
{% if attributes %}
{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

..
HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages.
.. autosummary::
:toctree:
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in attributes %}
{% if item in members and not item.startswith('_') %}
~{{ name }}.{{ item }}
{% endif %}
{%- endfor %}
{% endif %}
{% endblock %}

{% if methods %}
.. rubric:: {{ _('Methods') }}

{% endif %}
{% endblock %}
.. autosummary::
{% for item in methods %}
{% if item in members and (not item.startswith('_') or item in ['__call__']) %}
~{{ name }}.{{ item }}
{% endif %}
{%- endfor %}
{% endif %}
{% endblock %}
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
# to ensure that include files (partial pages) aren't built, exclude them
# https://github.com/sphinx-doc/sphinx/issues/1965#issuecomment-124732907
"**/includes/**",
"**/api/pandas.Series.dt.rst",
]
try:
import nbconvert
Expand Down Expand Up @@ -130,6 +129,8 @@
autodoc_typehints = "none"

# numpydoc
numpydoc_show_class_members = False
numpydoc_show_inherited_class_members = False
numpydoc_attributes_as_param_list = False

# matplotlib plot directive
Expand Down
29 changes: 13 additions & 16 deletions doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ pandas provides dtype-specific methods under various accessors.
These are separate namespaces within :class:`Series` that only apply
to specific data types.

.. autosummary::
:toctree: api/
:nosignatures:
:template: autosummary/accessor.rst

Series.str
Series.cat
Series.dt
Series.sparse
DataFrame.sparse
Index.str


=========================== =================================
Data Type Accessor
=========================== =================================
Expand Down Expand Up @@ -458,22 +471,6 @@ strings and apply several methods to it. These can be accessed like
Series.str.isdecimal
Series.str.get_dummies

..
The following is needed to ensure the generated pages are created with the
correct template (otherwise they would be created in the Series/Index class page)
..
.. autosummary::
:toctree: api/
:template: autosummary/accessor.rst
Series.str
Series.cat
Series.dt
Series.sparse
DataFrame.sparse
Index.str

.. _api.series.cat:

Categorical accessor
Expand Down

0 comments on commit eb98a47

Please sign in to comment.