10000 Merge pull request #11474 from eric-wieser/move-add-new-docs · numpy/numpy@4078856 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4078856

Browse files
authored
Merge pull request #11474 from eric-wieser/move-add-new-docs
MAINT: Move add_newdocs into core, since it only adds docs to those pieces
2 parents a854e70 + 2244cd9 commit 4078856

File tree

5 files changed

+43
-39
lines changed

5 files changed

+43
-39
lines changed

numpy/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ def pkgload(*packages, **options):
139139
loader = PackageLoader(infunc=True)
140140
return loader(*packages, **options)
141141

142-
from . import add_newdocs
143-
__all__ = ['add_newdocs',
144-
'ModuleDeprecationWarning',
142+
__all__ = ['ModuleDeprecationWarning',
145143
'VisibleDeprecationWarning']
146144

147145
pkgload.__doc__ = PackageLoader.__call__.__doc__

numpy/core/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
from .fromnumeric import amax as max, amin as min, round_ as round
6060
from .numeric import absolute as abs
6161

62+
# do this after everything else, to minimize the chance of this misleadingly
63+
# appearing in an import-time traceback
64+
from . import _add_newdocs
65+
6266
__all__ = ['char', 'rec', 'memmap']
6367
__all__ += numeric.__all__
6468
__all__ += fromnumeric.__all__

numpy/add_newdocs.py renamed to numpy/core/_add_newdocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111
from __future__ import division, absolute_import, print_function
1212

13-
from numpy.lib import add_newdoc
13+
from numpy.core.function_base import add_newdoc
1414

1515
###############################################################################
1616
#

numpy/core/function_base.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from . import numeric as _nx
77
from .numeric import (result_type, NaN, shares_memory, MAY_SHARE_BOUNDS,
88
TooHardError,asanyarray)
9+
from numpy.core.multiarray import add_docstring
910

1011
__all__ = ['logspace', 'linspace', 'geomspace']
1112

@@ -356,3 +357,38 @@ def geomspace(start, stop, num=50, endpoint=True, dtype=None):
356357
endpoint=endpoint, base=10.0, dtype=dtype)
357358

358359
return result.astype(dtype)
360+
361+
362+
#always succeed
363+
def add_newdoc(place, obj, doc):
364+
"""
365+
Adds documentation to obj which is in module place.
366+
367+
If doc is a string add it to obj as a docstring
368+
369+
If doc is a tuple, then the first element is interpreted as
370+
an attribute of obj and the second as the docstring
371+
(method, docstring)
372+
373+
If doc is a list, then each element of the list should be a
374+
sequence of length two --> [(method1, docstring1),
375+
(method2, docstring2), ...]
376+
377+
This routine never raises an error.
378+
379+
This routine cannot modify read-only docstrings, as appear
380+
in new-style classes or built-in functions. Because this
381+
routine never raises an error the caller must check manually
382+
that the docstrings were changed.
383+
"""
384+
try:
385+
new = getattr(__import__(place, globals(), {}, [obj]), obj)
386+
if isinstance(doc, str):
387+
add_docstring(new, doc.strip())
388+
elif isinstance(doc, tuple):
389+
add_docstring(getattr(new, doc[0]), doc[1].strip())
390+
elif isinstance(doc, list):
391+
for val in doc:
392+
add_docstring(getattr(new, val[0]), val[1].strip())
393+
except Exception:
394+
pass

numpy/lib/function_base.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ravel, nonzero, sort, partition, mean, any, sum
2828
)
2929
from numpy.core.numerictypes import typecodes, number
30+
from numpy.core.function_base import add_newdoc
3031
from numpy.lib.twodim_base import diag
3132
from .utils import deprecate
3233
from numpy.core.multiarray import (
@@ -3892,41 +3893,6 @@ def trapz(y, x=None, dx=1.0, axis=-1):
38923893
return ret
38933894

38943895

3895-
#always succeed
3896-
def add_newdoc(place, obj, doc):
3897-
"""
3898-
Adds documentation to obj which is in module place.
3899-
3900-
If doc is a string add it to obj as a docstring
3901-
3902-
If doc is a tuple, then the first element is interpreted as
3903-
an attribute of obj and the second as the docstring
3904-
(method, docstring)
3905-
3906-
If doc is a list, then each element of the list should be a
3907-
sequence of length two --> [(method1, docstring1),
3908-
(method2, docstring2), ...]
3909-
3910-
This routine never raises an error.
3911-
3912-
This routine cannot modify read-only docstrings, as appear
3913-
in new-style classes or built-in functions. Because this
3914-
routine never raises an error the caller must check manually
3915-
that the docstrings were changed.
3916-
"""
3917-
try:
3918-
new = getattr(__import__(place, globals(), {}, [obj]), obj)
3919-
if isinstance(doc, str):
3920-
add_docstring(new, doc.strip())
3921-
elif isinstance(doc, tuple):
3922-
add_docstring(getattr(new, doc[0]), doc[1].strip())
3923-
elif isinstance(doc, list):
3924-
for val in doc:
3925-
add_docstring(getattr(new, val[0]), val[1].strip())
3926-
except Exception:
3927-
pass
3928-
3929-
39303896
# Based on scitools meshgrid
39313897
def meshgrid(*xi, **kwargs):
39323898
"""

0 commit comments

Comments
 (0)
0