Skip to content

Commit c1fe54d

Browse files
FHaasePingviinituutti
authored andcommitted
DOC: Use official numpydoc extension (pandas-dev#24098)
* Use official numpydoc package - Replace custom numpydoc in `doc/sphinxext/numpydoc` with official numpydoc release - Remove `numpydoc_use_blockquotes` parameter Signed-off-by: Fabian Haase <[email protected]> * Add numpydoc package to travis Signed-off-by: Fabian Haase <[email protected]> * Use member listing for attributes Signed-off-by: Fabian Haase <[email protected]> * Move modification of SphinxDocString to conf.py Signed-off-by: Fabian Haase <[email protected]> * Update comments to be more descriptive Signed-off-by: Fabian Haase <[email protected]> * Fix linting Signed-off-by: Fabian Haase <[email protected]> * Review of @jorisvandenbossche Signed-off-by: Fabian Haase <[email protected]> * Fix linting Signed-off-by: Fabian Haase <[email protected]>
1 parent 29fed0e commit c1fe54d

13 files changed

+64
-2726
lines changed

ci/deps/travis-36-doc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121
- notebook
2222
- numexpr
2323
- numpy=1.13*
24+
- numpydoc
2425
- openpyxl
2526
- pandoc
2627
- pyarrow

doc/source/conf.py

+60-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import importlib
1919
import logging
2020
import warnings
21+
2122
from sphinx.ext.autosummary import _import_by_name
23+
from numpydoc.docscrape import NumpyDocString
24+
from numpydoc.docscrape_sphinx import SphinxDocString
2225

2326
logger = logging.getLogger(__name__)
2427

@@ -49,10 +52,6 @@
4952

5053
])
5154

52-
# numpydoc is available in the sphinxext directory, and can't be imported
53-
# until sphinxext is available in the Python path
54-
from numpydoc.docscrape import NumpyDocString
55-
5655
# -- General configuration -----------------------------------------------
5756

5857
# Add any Sphinx extension module names here, as strings. They can be
@@ -64,7 +63,7 @@
6463
'sphinx.ext.doctest',
6564
'sphinx.ext.extlinks',
6665
'sphinx.ext.todo',
67-
'numpydoc',
66+
'numpydoc', # handle NumPy documentation formatted docstrings
6867
'IPython.sphinxext.ipython_directive',
6968
'IPython.sphinxext.ipython_console_highlighting',
7069
'matplotlib.sphinxext.plot_directive',
@@ -91,12 +90,6 @@
9190
if any(re.match(r"\s*api\s*", l) for l in index_rst_lines):
9291
autosummary_generate = True
9392

94-
# numpydoc
95-
# for now use old parameter listing (styling + **kwargs problem)
96-
numpydoc_use_blockquotes = True
97-
# use member listing for attributes
98-
numpydoc_attributes_as_param_list = False
99-
10093
# matplotlib plot directive
10194
plot_include_source = True
10295
plot_formats = [("png", 90)]
@@ -411,6 +404,62 @@
411404
]
412405

413406

407+
def sphinxdocstring_str(self, indent=0, func_role="obj"):
408+
# Pandas displays Attributes section in style like Methods section
409+
410+
# Function is copy of `SphinxDocString.__str__`
411+
ns = {
412+
'signature': self._str_signature(),
413+
'index': self._str_index(),
414+
'summary': self._str_summary(),
415+
'extended_summary': self._str_extended_summary(),
416+
'parameters': self._str_param_list('Parameters'),
417+
'returns': self._str_returns('Returns'),
418+
'yields': self._str_returns('Yields'),
419+
'other_parameters': self._str_param_list('Other Parameters'),
420+
'raises': self._str_param_list('Raises'),
421+
'warns': self._str_param_list('Warns'),
422+
'warnings': self._str_warnings(),
423+
'see_also': self._str_see_also(func_role),
424+
'notes': self._str_section('Notes'),
425+
'references': self._str_references(),
426+
'examples': self._str_examples(),
427+
# Replaced `self._str_param_list('Attributes', fake_autosummary=True)`
428+
# with `self._str_member_list('Attributes')`
429+
'attributes': self._str_member_list('Attributes'),
430+
'methods': self._str_member_list('Methods'),
431+
}
432+
ns = {k: '\n'.join(v) for k, v in ns.items()}
433+
434+
rendered = self.template.render(**ns)
435+
return '\n'.join(self._str_indent(rendered.split('\n'), indent))
436+
437+
438+
SphinxDocString.__str__ = sphinxdocstring_str
439+
440+
441+
# Fix "WARNING: Inline strong start-string without end-string."
442+
# PR #155 "Escape the * in *args and **kwargs" from numpydoc
443+
# Can be removed after PR merges in v0.9.0
444+
def decorate_process_param(func):
445+
def _escape_args_and_kwargs(name):
446+
if name[:2] == '**':
447+
return r'\*\*' + name[2:]
448+
elif name[:1] == '*':
449+
return r'\*' + name[1:]
450+
else:
451+
return name
452+
453+
def func_wrapper(self, param, desc, fake_autosummary):
454+
param = _escape_args_and_kwargs(param.strip())
455+
return func(self, param, desc, fake_autosummary)
456+
457+
return func_wrapper
458+
459+
460+
func = SphinxDocString._process_param
461+
SphinxDocString._process_param = decorate_process_param(func)
462+
414463
# Add custom Documenter to handle attributes/methods of an AccessorProperty
415464
# eg pandas.Series.str and pandas.Series.dt (see GH9322)
416465

doc/sphinxext/numpydoc/LICENSE.txt

-94
This file was deleted.

doc/sphinxext/numpydoc/README.rst

-51
This file was deleted.

doc/sphinxext/numpydoc/__init__.py

-8
This file was deleted.

0 commit comments

Comments
 (0)