diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-09-02 10:06:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-02 10:06:54 -0500 |
commit | 3dbbfd8db5c21c603620bebc98e03bc84334f11c (patch) | |
tree | e29eb26cfbf72ee9b03aa15dd02671bf17e70301 /numpy/lib | |
parent | 9164f23c19c049e28d4d4825a53bbb01aedabcfc (diff) | |
parent | 68ea0c792db6bac435752e45d8681f7f1283453d (diff) | |
download | numpy-3dbbfd8db5c21c603620bebc98e03bc84334f11c.tar.gz |
Merge pull request #7148 from seberg/stacklevel+tests
ENH,TST: Bump stacklevel and add tests for warnings
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/format.py | 4 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 30 | ||||
-rw-r--r-- | numpy/lib/nanfunctions.py | 18 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 6 | ||||
-rw-r--r-- | numpy/lib/polynomial.py | 2 | ||||
-rw-r--r-- | numpy/lib/utils.py | 6 |
6 files changed, 33 insertions, 33 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index e62677bd8..633aee675 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -556,7 +556,7 @@ def write_array(fp, array, version=None, allow_pickle=True, pickle_kwargs=None): # this warning can be removed when 1.9 has aged enough if version != (2, 0) and used_ver == (2, 0): warnings.warn("Stored array in format 2.0. It can only be" - "read by NumPy >= 1.9", UserWarning) + "read by NumPy >= 1.9", UserWarning, stacklevel=2) if array.itemsize == 0: buffersize = 0 @@ -759,7 +759,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, # this warning can be removed when 1.9 has aged enough if version != (2, 0) and used_ver == (2, 0): warnings.warn("Stored array in format 2.0. It can only be" - "read by NumPy >= 1.9", UserWarning) + "read by NumPy >= 1.9", UserWarning, stacklevel=2) offset = fp.tell() finally: fp.close() diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index a866ed767..b74e04028 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1383,7 +1383,7 @@ def select(condlist, choicelist, default=0): # 2014-02-24, 1.9 warnings.warn("select with an empty condition list is not possible" "and will be deprecated", - DeprecationWarning) + DeprecationWarning, stacklevel=2) return np.asarray(default)[()] choicelist = [np.asarray(choice) for choice in choicelist] @@ -1418,7 +1418,7 @@ def select(condlist, choicelist, default=0): msg = "select condlists containing integer ndarrays is deprecated " \ "and will be removed in the future. Use `.astype(bool)` to " \ "convert to bools." - warnings.warn(msg, DeprecationWarning) + warnings.warn(msg, DeprecationWarning, stacklevel=2) if choicelist[0].ndim == 0: # This may be common, so avoid the call. @@ -2692,7 +2692,7 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, fact = w_sum - ddof*sum(w*aweights)/w_sum if fact <= 0: - warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning) + warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning, stacklevel=2) fact = 0.0 X -= avg[:, None] @@ -2766,7 +2766,7 @@ def corrcoef(x, y=None, rowvar=1, bias=np._NoValue, ddof=np._NoValue): if bias is not np._NoValue or ddof is not np._NoValue: # 2015-03-15, 1.10 warnings.warn('bias and ddof have no effect and are deprecated', - DeprecationWarning) + DeprecationWarning, stacklevel=2) c = cov(x, y, rowvar) try: d = diag(c) @@ -3774,7 +3774,7 @@ def _median(a, axis=None, out=None, overwrite_input=False): if rout.ndim == 0: if n == True: warnings.warn("Invalid value encountered in median", - RuntimeWarning) + RuntimeWarning, stacklevel=3) if out is not None: out[...] = a.dtype.type(np.nan) rout = out @@ -3783,7 +3783,7 @@ def _median(a, axis=None, out=None, overwrite_input=False): elif np.count_nonzero(n.ravel()) > 0: warnings.warn("Invalid value encountered in median for" + " %d results" % np.count_nonzero(n.ravel()), - RuntimeWarning) + RuntimeWarning, stacklevel=3) rout[n] = np.nan return rout else: @@ -4039,7 +4039,7 @@ def _percentile(a, q, axis=None, out=None, if np.any(n): warnings.warn("Invalid value encountered in percentile", - RuntimeWarning) + RuntimeWarning, stacklevel=3) if zerod: if ap.ndim == 1: if out is not None: @@ -4403,7 +4403,7 @@ def delete(arr, obj, axis=None): # 2013-09-24, 1.9 warnings.warn( "in the future the special handling of scalars will be removed " - "from delete and raise an error", DeprecationWarning) + "from delete and raise an error", DeprecationWarning, stacklevel=2) if wrap: return wrap(arr) else: @@ -4470,7 +4470,7 @@ def delete(arr, obj, axis=None): if obj.dtype == bool: warnings.warn( "in the future insert will treat boolean arrays and array-likes " - "as boolean index instead of casting it to integer", FutureWarning) + "as boolean index instead of casting it to integer", FutureWarning, stacklevel=2) obj = obj.astype(intp) if isinstance(_obj, (int, long, integer)): # optimization for a single value @@ -4498,7 +4498,7 @@ def delete(arr, obj, axis=None): # 2013-09-24, 1.9 warnings.warn( "using a non-integer array as obj in delete will result in an " - "error in the future", DeprecationWarning) + "error in the future", DeprecationWarning, stacklevel=2) obj = obj.astype(intp) keep = ones(N, dtype=bool) @@ -4509,13 +4509,13 @@ def delete(arr, obj, axis=None): warnings.warn( "in the future out of bounds indices will raise an error " "instead of being ignored by `numpy.delete`.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) obj = obj[inside_bounds] positive_indices = obj >= 0 if not positive_indices.all(): warnings.warn( "in the future negative indices will not be ignored by " - "`numpy.delete`.", FutureWarning) + "`numpy.delete`.", FutureWarning, stacklevel=2) obj = obj[positive_indices] keep[obj, ] = False @@ -4642,7 +4642,7 @@ def insert(arr, obj, values, axis=None): # 2013-09-24, 1.9 warnings.warn( "in the future the special handling of scalars will be removed " - "from insert and raise an error", DeprecationWarning) + "from insert and raise an error", DeprecationWarning, stacklevel=2) arr = arr.copy(order=arrorder) arr[...] = values if wrap: @@ -4664,7 +4664,7 @@ def insert(arr, obj, values, axis=None): warnings.warn( "in the future insert will treat boolean arrays and " "array-likes as a boolean index instead of casting it to " - "integer", FutureWarning) + "integer", FutureWarning, stacklevel=2) indices = indices.astype(intp) # Code after warning period: #if obj.ndim != 1: @@ -4714,7 +4714,7 @@ def insert(arr, obj, values, axis=None): # 2013-09-24, 1.9 warnings.warn( "using a non-integer array as obj in insert will result in an " - "error in the future", DeprecationWarning) + "error in the future", DeprecationWarning, stacklevel=2) indices = indices.astype(intp) indices[indices < 0] += N diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index c2fc92ebf..7f7aea9bc 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -236,7 +236,7 @@ def nanmin(a, axis=None, out=None, keepdims=np._NoValue): # Fast, but not safe for subclasses of ndarray res = np.fmin.reduce(a, axis=axis, out=out, **kwargs) if np.isnan(res).any(): - warnings.warn("All-NaN axis encountered", RuntimeWarning) + warnings.warn("All-NaN axis encountered", RuntimeWarning, stacklevel=2) else: # Slow, but safe for subclasses of ndarray a, mask = _replace_nan(a, +np.inf) @@ -248,7 +248,7 @@ def nanmin(a, axis=None, out=None, keepdims=np._NoValue): mask = np.all(mask, axis=axis, **kwargs) if np.any(mask): res = _copyto(res, np.nan, mask) - warnings.warn("All-NaN axis encountered", RuntimeWarning) + warnings.warn("All-NaN axis encountered", RuntimeWarning, stacklevel=2) return res @@ -343,7 +343,7 @@ def nanmax(a, axis=None, out=None, keepdims=np._NoValue): # Fast, but not safe for subclasses of ndarray res = np.fmax.reduce(a, axis=axis, out=out, **kwargs) if np.isnan(res).any(): - warnings.warn("All-NaN slice encountered", RuntimeWarning) + warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=2) else: # Slow, but safe for subclasses of ndarray a, mask = _replace_nan(a, -np.inf) @@ -355,7 +355,7 @@ def nanmax(a, axis=None, out=None, keepdims=np._NoValue): mask = np.all(mask, axis=axis, **kwargs) if np.any(mask): res = _copyto(res, np.nan, mask) - warnings.warn("All-NaN axis encountered", RuntimeWarning) + warnings.warn("All-NaN axis encountered", RuntimeWarning, stacklevel=2) return res @@ -821,7 +821,7 @@ def nanmean(a, axis=None, dtype=None, out=None, keepdims=np._NoValue): isbad = (cnt == 0) if isbad.any(): - warnings.warn("Mean of empty slice", RuntimeWarning) + warnings.warn("Mean of empty slice", RuntimeWarning, stacklevel=2) # NaN is the only possible bad value, so no further # action is needed to handle bad results. return avg @@ -835,7 +835,7 @@ def _nanmedian1d(arr1d, overwrite_input=False): c = np.isnan(arr1d) s = np.where(c)[0] if s.size == arr1d.size: - warnings.warn("All-NaN slice encountered", RuntimeWarning) + warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=3) return np.nan elif s.size == 0: return np.median(arr1d, overwrite_input=overwrite_input) @@ -887,7 +887,7 @@ def _nanmedian_small(a, axis=None, out=None, overwrite_input=False): a = np.ma.masked_array(a, np.isnan(a)) m = np.ma.median(a, axis=axis, overwrite_input=overwrite_input) for i in range(np.count_nonzero(m.mask.ravel())): - warnings.warn("All-NaN slice encountered", RuntimeWarning) + warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=3) if out is not None: out[...] = m.filled(np.nan) return out @@ -1161,7 +1161,7 @@ def _nanpercentile1d(arr1d, q, overwrite_input=False, interpolation='linear'): c = np.isnan(arr1d) s = np.where(c)[0] if s.size == arr1d.size: - warnings.warn("All-NaN slice encountered", RuntimeWarning) + warnings.warn("All-NaN slice encountered", RuntimeWarning, stacklevel=3) if q.ndim == 0: return np.nan else: @@ -1317,7 +1317,7 @@ def nanvar(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue): isbad = (dof <= 0) if np.any(isbad): - warnings.warn("Degrees of freedom <= 0 for slice.", RuntimeWarning) + warnings.warn("Degrees of freedom <= 0 for slice.", RuntimeWarning, stacklevel=2) # NaN, inf, or negative numbers are all possible bad # values, so explicitly replace them with NaN. var = _copyto(var, np.nan, isbad) diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 534aa695c..0b2fdfaba 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -944,7 +944,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, # End of lines reached first_line = '' first_vals = [] - warnings.warn('loadtxt: Empty input file: "%s"' % fname) + warnings.warn('loadtxt: Empty input file: "%s"' % fname, stacklevel=2) N = len(usecols or first_vals) dtype_types, packing = flatten_dtype(dtype) @@ -1542,7 +1542,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, # return an empty array if the datafile is empty first_line = asbytes('') first_values = [] - warnings.warn('genfromtxt: Empty input file: "%s"' % fname) + warnings.warn('genfromtxt: Empty input file: "%s"' % fname, stacklevel=2) # Should we take the first values as names ? if names is True: @@ -1827,7 +1827,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, raise ValueError(errmsg) # Issue a warning ? else: - warnings.warn(errmsg, ConversionWarning) + warnings.warn(errmsg, ConversionWarning, stacklevel=2) # Strip the last skip_footer data if skip_footer > 0: diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index d178ba4b3..81c72749a 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -588,7 +588,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): # warn on rank reduction, which indicates an ill conditioned matrix if rank != order and not full: msg = "Polyfit may be poorly conditioned" - warnings.warn(msg, RankWarning) + warnings.warn(msg, RankWarning, stacklevel=2) if full: return c, resids, rank, s, rcond diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index a2191468f..133704d13 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -96,7 +96,7 @@ class _Deprecate(object): def newfunc(*args,**kwds): """`arrayrange` is deprecated, use `arange` instead!""" - warnings.warn(depdoc, DeprecationWarning) + warnings.warn(depdoc, DeprecationWarning, stacklevel=2) return func(*args, **kwds) newfunc = _set_function_name(newfunc, old_name) @@ -152,7 +152,7 @@ def deprecate(*args, **kwargs): >>> olduint(6) /usr/lib/python2.5/site-packages/numpy/lib/utils.py:114: DeprecationWarning: uint32 is deprecated - warnings.warn(str1, DeprecationWarning) + warnings.warn(str1, DeprecationWarning, stacklevel=2) 6 """ @@ -1016,7 +1016,7 @@ class SafeEval(object): def __init__(self): # 2014-10-15, 1.10 warnings.warn("SafeEval is deprecated in 1.10 and will be removed.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) def visit(self, node): cls = node.__class__ |