From 250861059b106371cb232456eeccd6d9e97d8f00 Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Wed, 14 Nov 2018 11:36:59 -0800 Subject: TST, DOC: enable refguide_check * ported the refguide_check module from SciPy for usage in NumPy docstring execution/ verification; added the refguide_check run to Azure Mac OS CI * adjusted NumPy docstrings such that refguide_check passes --- numpy/lib/utils.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 84edf4021..1c834e7f2 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -151,9 +151,6 @@ def deprecate(*args, **kwargs): >>> olduint = np.deprecate(np.uint) >>> olduint(6) - /usr/lib/python2.5/site-packages/numpy/lib/utils.py:114: - DeprecationWarning: uint32 is deprecated - warnings.warn(str1, DeprecationWarning, stacklevel=2) 6 """ @@ -202,7 +199,7 @@ def byte_bounds(a): >>> high - low == I.size*I.itemsize True >>> I = np.eye(2, dtype='G'); I.dtype - dtype('complex192') + dtype('complex256') >>> low, high = np.byte_bounds(I) >>> high - low == I.size*I.itemsize True @@ -263,17 +260,17 @@ def who(vardict=None): >>> np.who() Name Shape Bytes Type =========================================================== - a 10 40 int32 + a 10 80 int64 b 20 160 float64 - Upper bound on total bytes = 200 + Upper bound on total bytes = 240 >>> d = {'x': np.arange(2.0), 'y': np.arange(3.0), 'txt': 'Some str', ... 'idx':5} >>> np.who(d) Name Shape Bytes Type =========================================================== - y 3 24 float64 x 2 16 float64 + y 3 24 float64 Upper bound on total bytes = 40 """ @@ -733,7 +730,7 @@ def lookfor(what, module=None, import_modules=True, regenerate=False, Examples -------- - >>> np.lookfor('binary representation') + >>> np.lookfor('binary representation') # doctest: +SKIP Search results for 'binary representation' ------------------------------------------ numpy.binary_repr @@ -1104,7 +1101,7 @@ def safe_eval(source): >>> np.safe_eval('open("/home/user/.ssh/id_dsa").read()') Traceback (most recent call last): ... - SyntaxError: Unsupported source construct: compiler.ast.CallFunc + ValueError: malformed node or string: <_ast.Call object at 0x...> """ # Local import to speed up numpy's import time. -- cgit v1.2.1 From 19784177a61de75927a4934fd4cdd91afbb5b35c Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Tue, 4 Dec 2018 12:17:59 -0800 Subject: MAINT: address several reviewer comments --- numpy/lib/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 1c834e7f2..355b66df9 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -198,8 +198,8 @@ def byte_bounds(a): >>> low, high = np.byte_bounds(I) >>> high - low == I.size*I.itemsize True - >>> I = np.eye(2, dtype='G'); I.dtype - dtype('complex256') + >>> I = np.eye(2); I.dtype + dtype('complex256') # may vary >>> low, high = np.byte_bounds(I) >>> high - low == I.size*I.itemsize True -- cgit v1.2.1 From 0bdc587d6cf5e6806e95d9debcafe62ac9f1d7fa Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Wed, 5 Dec 2018 11:15:28 -0800 Subject: MAINT: addressing review comments * restored regression comment in numpy/core/defchararray.py * fixed the dimensionality of the z array in all() docstring in numpy/core/fromnumeric.py; this isn't detected because it is in-line with variable memory addresses which are tagged as variable for refguide * byte_bounds() docstring adjusted to reflect non-variable dtype after reviewer requested removal of complex dtype * restore an original comment in matmul docstring, as requested by reviewer --- numpy/lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 355b66df9..34d089893 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -199,7 +199,7 @@ def byte_bounds(a): >>> high - low == I.size*I.itemsize True >>> I = np.eye(2); I.dtype - dtype('complex256') # may vary + dtype('float64') >>> low, high = np.byte_bounds(I) >>> high - low == I.size*I.itemsize True -- cgit v1.2.1 From 28f8a85b9ece5773a8ac75ffcd2502fc93612eff Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Wed, 5 Dec 2018 14:59:57 -0800 Subject: MAINT: include recfunctions module * added lib.recfunctions to refguide PUBLIC_SUBMODULES, as the doctests were otherwise not getting executed * fixed a failing doctest in recfunctions after above activation --- numpy/lib/utils.py | 1 + 1 file changed, 1 insertion(+) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 34d089893..5a4cae235 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -150,6 +150,7 @@ def deprecate(*args, **kwargs): Warning: >>> olduint = np.deprecate(np.uint) + DeprecationWarning: `uint64` is deprecated! # may vary >>> olduint(6) 6 -- cgit v1.2.1 From 217f13b955df24ba3314802071dd04b1262e1320 Mon Sep 17 00:00:00 2001 From: mattip Date: Sun, 6 Jan 2019 13:56:47 +0200 Subject: ENH: remove "Invalid value" warnings from median, percentile --- numpy/lib/utils.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 5a4cae235..6b112f37a 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1140,17 +1140,12 @@ def _median_nancheck(data, result, axis, out): n = n.filled(False) if result.ndim == 0: if n == True: - warnings.warn("Invalid value encountered in median", - RuntimeWarning, stacklevel=3) if out is not None: out[...] = data.dtype.type(np.nan) result = out else: result = data.dtype.type(np.nan) elif np.count_nonzero(n.ravel()) > 0: - warnings.warn("Invalid value encountered in median for" + - " %d results" % np.count_nonzero(n.ravel()), - RuntimeWarning, stacklevel=3) result[n] = np.nan return result -- cgit v1.2.1 From af8dda19fad8cf736bd042ed7aae65d1e8c8553e Mon Sep 17 00:00:00 2001 From: wrwrwr Date: Sun, 9 Oct 2016 22:34:38 +0200 Subject: BUG: Fix help() formatting for deprecated functions. Closes #8058. --- numpy/lib/utils.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 6b112f37a..718b55c4b 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -105,6 +105,20 @@ class _Deprecate(object): if doc is None: doc = depdoc else: + lines = doc.expandtabs().split('\n') + indent = _get_indent(lines[1:]) + if lines[0].lstrip(): + # Indent the original first line to let inspect.cleandoc() + # dedent the docstring despite the deprecation notice. + doc = indent * ' ' + doc + else: + # Remove the same leading blank lines as cleandoc() would. + skip = len(lines[0]) + 1 + for line in lines[1:]: + if len(line) > indent: + break + skip += len(line) + 1 + doc = doc[skip:] doc = '\n\n'.join([depdoc, doc]) newfunc.__doc__ = doc try: @@ -115,6 +129,21 @@ class _Deprecate(object): newfunc.__dict__.update(d) return newfunc + +def _get_indent(lines): + """ + Determines the leading whitespace that could be removed from all the lines. + """ + indent = sys.maxsize + for line in lines: + content = len(line.lstrip()) + if content: + indent = min(indent, len(line) - content) + if indent == sys.maxsize: + indent = 0 + return indent + + def deprecate(*args, **kwargs): """ Issues a DeprecationWarning, adds warning to `old_name`'s -- cgit v1.2.1 From 4c35a853c2a09de5bdb236aa6bd97aa5ea18f195 Mon Sep 17 00:00:00 2001 From: kritisingh1 Date: Wed, 3 Apr 2019 22:55:50 +0530 Subject: Issue deprecation warnings --- numpy/lib/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 718b55c4b..188a99d92 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1098,6 +1098,9 @@ def safe_eval(source): Evaluate a string containing a Python literal expression without allowing the execution of arbitrary non-literal code. + .. deprecate:: 1.17 + safe_eval is deprecated + Parameters ---------- source : str @@ -1137,6 +1140,9 @@ def safe_eval(source): # Local import to speed up numpy's import time. import ast + # Numpy 1.17 + warnings.warn("SafeEval is deprecated in 1.17", + DeprecationWarning, stacklevel=2) return ast.literal_eval(source) -- cgit v1.2.1 From 67b53e1d3017171235b155a898e54f4bb8a41d47 Mon Sep 17 00:00:00 2001 From: kritisingh1 Date: Wed, 10 Apr 2019 17:10:31 +0530 Subject: Fix tests --- numpy/lib/utils.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 188a99d92..27e055328 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1139,10 +1139,6 @@ def safe_eval(source): """ # Local import to speed up numpy's import time. import ast - - # Numpy 1.17 - warnings.warn("SafeEval is deprecated in 1.17", - DeprecationWarning, stacklevel=2) return ast.literal_eval(source) -- cgit v1.2.1 From 13561bd89d67bd101cdb195f003ae1e34c6a5b52 Mon Sep 17 00:00:00 2001 From: kritisingh1 Date: Fri, 7 Jun 2019 21:46:42 +0530 Subject: fix tests --- numpy/lib/utils.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 27e055328..c7dbcc5f9 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1098,9 +1098,6 @@ def safe_eval(source): Evaluate a string containing a Python literal expression without allowing the execution of arbitrary non-literal code. - .. deprecate:: 1.17 - safe_eval is deprecated - Parameters ---------- source : str -- cgit v1.2.1