summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2013-10-28 14:44:42 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2014-02-06 17:51:59 +0100
commit854400057f0287b80cfac42e16f98d0daa097aed (patch)
tree0dead0b93b8a891834ead700fba3701dad51167a
parent628f60db43282e87a56e98561211ad04cf55eed7 (diff)
downloadnumpy-854400057f0287b80cfac42e16f98d0daa097aed.tar.gz
TST: Add deprecation tests
-rw-r--r--numpy/core/src/multiarray/mapping.c1
-rw-r--r--numpy/core/tests/test_deprecations.py50
2 files changed, 50 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 3cd13c1ce..23010477e 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -2094,6 +2094,7 @@ PyArray_MapIterNext(PyArrayMapIterObject *mit)
*
* @param MapIterObject
* @param The parsed indices object
+ * @param Number of indices
* @param The array that is being iterated
*
* Sets the following information:
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 983df884b..41f1cf744 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -11,7 +11,8 @@ import warnings
from nose.plugins.skip import SkipTest
import numpy as np
-from numpy.testing import dec, run_module_suite, assert_raises
+from numpy.testing import (dec, run_module_suite, assert_raises,
+ assert_warns, assert_array_equal)
class _DeprecationTestCase(object):
@@ -295,5 +296,52 @@ class TestArrayToIndexDeprecation(_DeprecationTestCase):
self.assert_deprecated(lambda: a[a:a:a], exceptions=(), num=3)
+class TestNonIntegerArrayLike(_DeprecationTestCase):
+ """Tests that array likes, i.e. lists give a deprecation warning
+ when they cannot be safely cast to an integer.
+ """
+ message = "non integer \(and non boolean\) array-likes will not be " \
+ "accepted as indices in the future"
+
+ def test_basic(self):
+ a = np.arange(10)
+ self.assert_deprecated(a.__getitem__, args=([0.5, 1.5],),
+ exceptions=IndexError)
+ self.assert_deprecated(a.__getitem__, args=((['1', '2'],),),
+ exceptions=IndexError)
+
+ self.assert_not_deprecated(a.__getitem__, ([],))
+
+
+ def test_boolean_futurewarning(self):
+ a = np.arange(10)
+ with warnings.catch_warnings():
+ warnings.filterwarnings('always')
+ assert_warns(FutureWarning, a.__getitem__, [True])
+ # Unfortunatly, the deprecation warning takes precedence:
+ #assert_warns(FutureWarning, a.__getitem__, True)
+
+ with warnings.catch_warnings():
+ warnings.filterwarnings('error')
+ assert_raises(FutureWarning, a.__getitem__, [True])
+ #assert_raises(FutureWarning, a.__getitem__, True)
+
+
+class TestMultipleEllipsisDeprecation(_DeprecationTestCase):
+ message = "an index can only have a single Ellipsis \(`...`\); replace " \
+ "all but one with slices \(`:`\)."
+
+ def test_basic(self):
+ a = np.arange(10)
+ self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))
+
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore', '', DeprecationWarning)
+ # Just check that this works:
+ b = a[...,...]
+ assert_array_equal(a, b)
+ assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
+
+
if __name__ == "__main__":
run_module_suite()