Skip to content

Commit fddc261

Browse files
committed
rewrite numpy docstrings
1 parent 0112190 commit fddc261

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

xarray/ufuncs.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Once NumPy 1.10 comes out with support for overriding ufuncs, this module will
1414
hopefully no longer be necessary.
1515
"""
16+
import textwrap
1617
import warnings as _warnings
1718

1819
import numpy as _np
@@ -78,10 +79,36 @@ def __call__(self, *args, **kwargs):
7879
return res
7980

8081

82+
def _skip_signature(doc):
83+
if doc.startswith(name):
84+
signature_end = doc.find("\n\n")
85+
doc = doc[signature_end + 2 :]
86+
87+
return doc
88+
89+
90+
def _remove_unused_reference_labels(doc):
91+
max_references = 5
92+
for num in range(max_references):
93+
label = f".. [{num}]"
94+
reference = f"[{num}]_"
95+
index = f"{num}. "
96+
97+
if label not in doc or reference in doc:
98+
continue
99+
100+
doc = doc.replace(label, index)
101+
102+
return doc
103+
104+
81105
def _create_op(name):
82106
func = _UFuncDispatcher(name)
83107
func.__name__ = name
84-
doc = getattr(_np, name).__doc__
108+
doc = _remove_unused_reference_labels(
109+
_skip_signature(textwrap.dedent(getattr(_np, name).__doc__))
110+
)
111+
85112
func.__doc__ = (
86113
"xarray specific variant of numpy.%s. Handles "
87114
"xarray.Dataset, xarray.DataArray, xarray.Variable, "

0 commit comments

Comments
 (0)