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/core | |
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/core')
-rw-r--r-- | numpy/core/_methods.py | 5 | ||||
-rw-r--r-- | numpy/core/fromnumeric.py | 2 | ||||
-rw-r--r-- | numpy/core/numeric.py | 10 | ||||
-rw-r--r-- | numpy/core/setup.py | 2 | ||||
-rw-r--r-- | numpy/core/setup_common.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 2 |
6 files changed, 13 insertions, 10 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index 5fc2bc445..54e267541 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -56,7 +56,7 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False): rcount = _count_reduce_items(arr, axis) # Make this warning show up first if rcount == 0: - warnings.warn("Mean of empty slice.", RuntimeWarning) + warnings.warn("Mean of empty slice.", RuntimeWarning, stacklevel=2) # Cast bool, unsigned int, and int to float64 by default if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)): @@ -79,7 +79,8 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): rcount = _count_reduce_items(arr, axis) # Make this warning show up on top. if ddof >= rcount: - warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning) + warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning, + stacklevel=2) # Cast bool, unsigned int, and int to float64 by default if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)): diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index d07c5c08b..99173d105 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -2647,7 +2647,7 @@ def rank(a): warnings.warn( "`rank` is deprecated; use the `ndim` attribute or function instead. " "To find the rank of a matrix see `numpy.linalg.matrix_rank`.", - VisibleDeprecationWarning) + VisibleDeprecationWarning, stacklevel=2) try: return a.ndim except AttributeError: diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 8db4e1302..81ed0178a 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1181,7 +1181,8 @@ def alterdot(): """ # 2014-08-13, 1.10 - warnings.warn("alterdot no longer does anything.", DeprecationWarning) + warnings.warn("alterdot no longer does anything.", + DeprecationWarning, stacklevel=2) def restoredot(): @@ -1205,7 +1206,8 @@ def restoredot(): """ # 2014-08-13, 1.10 - warnings.warn("restoredot no longer does anything.", DeprecationWarning) + warnings.warn("restoredot no longer does anything.", + DeprecationWarning, stacklevel=2) def tensordot(a, b, axes=2): @@ -2260,8 +2262,8 @@ def binary_repr(num, width=None): if width is not None and width < binwidth: warnings.warn( "Insufficient bit width provided. This behavior " - "will raise an error in the future.", DeprecationWarning - ) + "will raise an error in the future.", DeprecationWarning, + stacklevel=3) if num == 0: return '0' * (width or 1) diff --git a/numpy/core/setup.py b/numpy/core/setup.py index c6c1f6c03..bec358480 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -179,7 +179,7 @@ def check_complex(config, mathlibs): try: if os.uname()[0] == "Interix": - warnings.warn("Disabling broken complex support. See #1365") + warnings.warn("Disabling broken complex support. See #1365", stacklevel=2) return priv, pub except: # os.uname not available on all platforms. blanket except ugly but safe diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py index ba7521e30..90b592999 100644 --- a/numpy/core/setup_common.py +++ b/numpy/core/setup_common.py @@ -94,7 +94,7 @@ def check_api_version(apiversion, codegen_dir): ) warnings.warn(msg % (apiversion, curapi_hash, apiversion, api_hash, __file__), - MismatchCAPIWarning) + MismatchCAPIWarning, stacklevel=2) # Mandatory functions: if not found, fail the build MANDATORY_FUNCS = ["sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs", "floor", "ceil", "sqrt", "log10", "log", "exp", "asin", diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index e03edb2ea..47870581a 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -641,7 +641,7 @@ class TestTestDeprecated(object): lambda: None) def foo(): - warnings.warn("foo", category=DeprecationWarning) + warnings.warn("foo", category=DeprecationWarning, stacklevel=2) test_case_instance.assert_deprecated(foo) test_case_instance.tearDown() |