8000 MAINT: Move add_newdocs into core, since it only adds docs to those pieces by eric-wieser · Pull Request #11474 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Move add_newdocs into core, since it only adds docs to those pieces #11474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def pkgload(*packages, **options):
loader = PackageLoader(infunc=True)
return loader(*packages, **options)

from . import add_newdocs
__all__ = ['add_newdocs',
'ModuleDeprecationWarning',
__all__ = ['ModuleDeprecationWarning',
'VisibleDeprecationWarning']

pkgload.__doc__ = PackageLoader.__call__.__doc__
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
from .fromnumeric import amax as max, amin as min, round_ as round
from .numeric import absolute as abs

# do this after everything else, to minimize the chance of this misleadingly
# appearing in an import-time traceback
from . import _add_newdocs

__all__ = ['char', 'rec', 'memmap']
__all__ += numeric.__all__
__all__ += fromnumeric.__all__
Expand Down
2 changes: 1 addition & 1 deletion numpy/add_newdocs.py → numpy/core/_add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
from __future__ import division, absolute_import, print_function

from numpy.lib import add_newdoc
from numpy.core.function_base import add_newdoc

###############################################################################
#
Expand Down
36 changes: 36 additions & 0 deletions numpy/core/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import numeric as _nx
from .numeric import (result_type, NaN, shares_memory, MAY_SHARE_BOUNDS,
TooHardError,asanyarray)
from numpy.core.multiarray import add_docstring

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

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

return result.astype(dtype)


#always succeed
def add_newdoc(place, obj, doc):
"""
Adds documentation to obj which is in module place.

If doc is a string add it to obj as a docstring

If doc is a tuple, then the first element is interpreted as
an attribute of obj and the second as the docstring
(method, docstring)

If doc is a list, then each element of the list should be a
sequence of length two --> [(method1, docstring1),
(method2, docstring2), ...]

This routine never raises an error.

This routine cannot modify read-only docstrings, as appear
in new-style classes or built-in functions. Because this
routine never raises an error the caller must check manually
that the docstrings were changed.
"""
try:
new = getattr(__import__(place, globals(), {}, [obj]), obj)
if isinstance(doc, str):
add_docstring(new, doc.strip())
elif isinstance(doc, tuple):
add_docstring(getattr(new, doc[0]), doc[1].strip())
elif isinstance(doc, list):
for val in doc:
add_docstring(getattr(new, val[0]), val[1].strip())
except Exception:
pass
36 changes: 1 addition & 35 deletions numpy/lib/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ravel, nonzero, sort, partition, mean, any, sum
)
from numpy.core.numerictypes import typecodes, number
from numpy.core.function_base import add_newdoc
from numpy.lib.twodim_base import diag
from .utils import deprecate
from numpy.core.multiarray import (
Expand Down Expand Up @@ -3892,41 +3893,6 @@ def trapz(y, x=None, dx=1.0, axis=-1):
return ret


#always succeed
def add_newdoc(place, obj, doc):
"""
Adds documentation to obj which is in module place.

If doc is a string add it to obj as a docstring

If doc is a tuple, then the first element is interpreted as
an attribute of obj and the second as the docstring
(method, docstring)

If doc is a list, then each element of the list should be a
sequence of length two --> [(method1, docstring1),
(method2, docstring2), ...]

This routine never raises an error.

This routine cannot modify read-only docstrings, as appear
in new-style classes or built-in functions. Because this
routine never raises an error the caller must check manually
that the docstrings were changed.
"""
try:
new = getattr(__import__(place, globals(), {}, [obj]), obj)
if isinstance(doc, str):
add_docstring(new, doc.strip())
elif isinstance(doc, tuple):
add_docstring(getattr(new, doc[0]), doc[1].strip())
elif isinstance(doc, list):
for val in doc:
add_docstring(getattr(new, val[0]), val[1].strip())
except Exception:
pass


# Based on scitools meshgrid
def meshgrid(*xi, **kwargs):
"""
Expand Down
0