Python numpy 模块,VisibleDeprecationWarning() 实例源码

我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用numpy.VisibleDeprecationWarning()

项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_simple(self):
        arr = np.ones((5, 4, 3))
        index = np.array([True])
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
                     arr.__getitem__, index)

        index = np.array([False] * 6)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)

        index = np.zeros((4, 4), dtype=bool)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)
        #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, (slice(None), index))
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_simple(self):
        arr = np.ones((5, 4, 3))
        index = np.array([True])
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
                     arr.__getitem__, index)

        index = np.array([False] * 6)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)

        index = np.zeros((4, 4), dtype=bool)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)
        #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, (slice(None), index))
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_simple(self):
        arr = np.ones((5, 4, 3))
        index = np.array([True])
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
                     arr.__getitem__, index)

        index = np.array([False] * 6)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)

        index = np.zeros((4, 4), dtype=bool)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)
        #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, (slice(None), index))
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_simple(self):
        arr = np.ones((5, 4, 3))
        index = np.array([True])
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
                     arr.__getitem__, index)

        index = np.array([False] * 6)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)

        index = np.zeros((4, 4), dtype=bool)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)
        #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, (slice(None), index))
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_simple(self):
        arr = np.ones((5, 4, 3))
        index = np.array([True])
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
                     arr.__getitem__, index)

        index = np.array([False] * 6)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)

        index = np.zeros((4, 4), dtype=bool)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)
        #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, (slice(None), index))
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_numpy_reloading():
    # gh-7844. Also check that relevant globals retain their identity.
    import numpy as np
    import numpy._globals

    _NoValue = np._NoValue
    VisibleDeprecationWarning = np.VisibleDeprecationWarning
    ModuleDeprecationWarning = np.ModuleDeprecationWarning

    reload(np)
    assert_(_NoValue is np._NoValue)
    assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
    assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)

    assert_raises(RuntimeError, reload, numpy._globals)
    reload(np)
    assert_(_NoValue is np._NoValue)
    assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
    assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with suppress_warnings() as sup:
            sup.filter(DeprecationWarning)
            sup.filter(FutureWarning)
            sup.filter(np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_numpy_reloading():
    # gh-7844. Also check that relevant globals retain their identity.
    import numpy as np
    import numpy._globals

    _NoValue = np._NoValue
    VisibleDeprecationWarning = np.VisibleDeprecationWarning
    ModuleDeprecationWarning = np.ModuleDeprecationWarning

    reload(np)
    assert_(_NoValue is np._NoValue)
    assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
    assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)

    assert_raises(RuntimeError, reload, numpy._globals)
    reload(np)
    assert_(_NoValue is np._NoValue)
    assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning)
    assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def assert_no_warnings(func, *args, **kw):
    # XXX: once we may depend on python >= 2.6, this can be replaced by the

    # warnings module context manager.
    # very important to avoid uncontrolled state propagation
    clean_warning_registry()
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')

        result = func(*args, **kw)
        if hasattr(np, 'VisibleDeprecationWarning'):
            # Filter out numpy-specific warnings in numpy >= 1.9
            w = [e for e in w
                 if e.category is not np.VisibleDeprecationWarning]

        if len(w) > 0:
            raise AssertionError("Got warnings when calling %s: %s"
                                 % (func.__name__, w))
    return result
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_bool_flat_indexing_invalid_nr_elements(self, level=rlevel):
        s = np.ones(10, dtype=float)
        x = np.array((15,), dtype=float)

        def ia(x, s, v):
            x[(s > 0)] = v

        # After removing deprecation, the following are ValueErrors.
        # This might seem odd as compared to the value error below. This
        # is due to the fact that the new code always uses "nonzero" logic
        # and the boolean special case is not taken.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            warnings.simplefilter('ignore', np.VisibleDeprecationWarning)
            self.assertRaises(IndexError, ia, x, s, np.zeros(9, dtype=float))
            self.assertRaises(IndexError, ia, x, s, np.zeros(11, dtype=float))
        # Old special case (different code path):
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(9, dtype=float))
        self.assertRaises(ValueError, ia, x.flat, s, np.zeros(11, dtype=float))
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_simple(self):
        arr = np.ones((5, 4, 3))
        index = np.array([True])
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
                     arr.__getitem__, index)

        index = np.array([False] * 6)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)

        index = np.zeros((4, 4), dtype=bool)
        #self.assert_deprecated(arr.__getitem__, args=(index,))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, index)
        #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
        assert_warns(np.VisibleDeprecationWarning,
             arr.__getitem__, (slice(None), index))
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def setUp(self):
        self.warn_ctx = warnings.catch_warnings(record=True)
        self.log = self.warn_ctx.__enter__()

        # Do *not* ignore other DeprecationWarnings. Ignoring warnings
        # can give very confusing results because of
        # http://bugs.python.org/issue4180 and it is probably simplest to
        # try to keep the tests cleanly giving only the right warning type.
        # (While checking them set to "error" those are ignored anyway)
        # We still have them show up, because otherwise they would be raised
        warnings.filterwarnings("always", category=np.VisibleDeprecationWarning)
        warnings.filterwarnings("always", message=self.message,
                                category=np.VisibleDeprecationWarning)
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_basic(self):
        a = np.arange(10)
        self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', '', np.VisibleDeprecationWarning)
            # Just check that this works:
            b = a[...,...]
            assert_array_equal(a, b)
            assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def rank(obj):
    """
    maskedarray version of the numpy function.

    .. note::
        Deprecated since 1.10.0

    """
    # 2015-04-12, 1.10.0
    warnings.warn(
        "`rank` is deprecated; use the `ndim` function instead. ",
        np.VisibleDeprecationWarning)
    return np.ndim(getdata(obj))
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def setUp(self):
        self.warn_ctx = warnings.catch_warnings(record=True)
        self.log = self.warn_ctx.__enter__()

        # Do *not* ignore other DeprecationWarnings. Ignoring warnings
        # can give very confusing results because of
        # http://bugs.python.org/issue4180 and it is probably simplest to
        # try to keep the tests cleanly giving only the right warning type.
        # (While checking them set to "error" those are ignored anyway)
        # We still have them show up, because otherwise they would be raised
        warnings.filterwarnings("always", category=np.VisibleDeprecationWarning)
        warnings.filterwarnings("always", message=self.message,
                                category=np.VisibleDeprecationWarning)
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_basic(self):
        a = np.arange(10)
        self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', '', np.VisibleDeprecationWarning)
            # Just check that this works:
            b = a[...,...]
            assert_array_equal(a, b)
            assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def rank(obj):
    """
    maskedarray version of the numpy function.

    .. note::
        Deprecated since 1.10.0

    """
    # 2015-04-12, 1.10.0
    warnings.warn(
        "`rank` is deprecated; use the `ndim` function instead. ",
        np.VisibleDeprecationWarning)
    return np.ndim(getdata(obj))
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def issue_deprecation_warning(msg):
    from numpy import VisibleDeprecationWarning
    warnings.warn(msg, VisibleDeprecationWarning, stacklevel=3)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test(self):
        a = np.arange(10)
        assert_warns(np.VisibleDeprecationWarning, np.rank, a)
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test(self):
        a = np.arange(10)
        assert_warns(np.VisibleDeprecationWarning, np.rank, a)
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def setUp(self):
        self.warn_ctx = warnings.catch_warnings(record=True)
        self.log = self.warn_ctx.__enter__()

        # Do *not* ignore other DeprecationWarnings. Ignoring warnings
        # can give very confusing results because of
        # http://bugs.python.org/issue4180 and it is probably simplest to
        # try to keep the tests cleanly giving only the right warning type.
        # (While checking them set to "error" those are ignored anyway)
        # We still have them show up, because otherwise they would be raised
        warnings.filterwarnings("always", category=np.VisibleDeprecationWarning)
        warnings.filterwarnings("always", message=self.message,
                                category=np.VisibleDeprecationWarning)
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_basic(self):
        a = np.arange(10)
        self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', '', np.VisibleDeprecationWarning)
            # Just check that this works:
            b = a[...,...]
            assert_array_equal(a, b)
            assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def rank(obj):
    """
    maskedarray version of the numpy function.

    .. note::
        Deprecated since 1.10.0

    """
    # 2015-04-12, 1.10.0
    warnings.warn(
        "`rank` is deprecated; use the `ndim` function instead. ",
        np.VisibleDeprecationWarning)
    return np.ndim(getdata(obj))
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def setUp(self):
        self.warn_ctx = warnings.catch_warnings(record=True)
        self.log = self.warn_ctx.__enter__()

        # Do *not* ignore other DeprecationWarnings. Ignoring warnings
        # can give very confusing results because of
        # http://bugs.python.org/issue4180 and it is probably simplest to
        # try to keep the tests cleanly giving only the right warning type.
        # (While checking them set to "error" those are ignored anyway)
        # We still have them show up, because otherwise they would be raised
        warnings.filterwarnings("always", category=np.VisibleDeprecationWarning)
        warnings.filterwarnings("always", message=self.message,
                                category=np.VisibleDeprecationWarning)
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test(self):
        a = np.arange(10)
        assert_warns(np.VisibleDeprecationWarning, np.rank, a)
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def rank(obj):
    """
    maskedarray version of the numpy function.

    .. note::
        Deprecated since 1.10.0

    """
    # 2015-04-12, 1.10.0
    warnings.warn(
        "`rank` is deprecated; use the `ndim` function instead. ",
        np.VisibleDeprecationWarning, stacklevel=2)
    return np.ndim(getdata(obj))
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_multidim(self):
        # Automatically test combinations with complex indexes on 2nd (or 1st)
        # spot and the simple ones in one other spot.
        with warnings.catch_warnings():
            # This is so that np.array(True) is not accepted in a full integer
            # index, when running the file separately.
            warnings.filterwarnings('error', '', DeprecationWarning)
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)

            def isskip(idx):
                return isinstance(idx, str) and idx == "skip"

            for simple_pos in [0, 2, 3]:
                tocheck = [self.fill_indices, self.complex_indices,
                           self.fill_indices, self.fill_indices]
                tocheck[simple_pos] = self.simple_indices
                for index in product(*tocheck):
                    index = tuple(i for i in index if not isskip(i))
                    self._check_multi_index(self.a, index)
                    self._check_multi_index(self.b, index)

        # Check very simple item getting:
        self._check_multi_index(self.a, (0, 0, 0, 0))
        self._check_multi_index(self.b, (0, 0, 0, 0))
        # Also check (simple cases of) too many indices:
        assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
        assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
        assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_1d(self):
        a = np.arange(10)
        with warnings.catch_warnings():
            warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
            for index in self.complex_indices:
                self._check_single_index(a, index)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def setUp(self):
        self.warn_ctx = warnings.catch_warnings(record=True)
        self.log = self.warn_ctx.__enter__()

        # Do *not* ignore other DeprecationWarnings. Ignoring warnings
        # can give very confusing results because of
        # http://bugs.python.org/issue4180 and it is probably simplest to
        # try to keep the tests cleanly giving only the right warning type.
        # (While checking them set to "error" those are ignored anyway)
        # We still have them show up, because otherwise they would be raised
        warnings.filterwarnings("always", category=np.VisibleDeprecationWarning)
        warnings.filterwarnings("always", message=self.message,
                                category=np.VisibleDeprecationWarning)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_basic(self):
        a = np.arange(10)
        self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', '', np.VisibleDeprecationWarning)
            # Just check that this works:
            b = a[...,...]
            assert_array_equal(a, b)
            assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def rank(obj):
    """
    maskedarray version of the numpy function.

    .. note::
        Deprecated since 1.10.0

    """
    # 2015-04-12, 1.10.0
    warnings.warn(
        "`rank` is deprecated; use the `ndim` function instead. ",
        np.VisibleDeprecationWarning)
    return np.ndim(getdata(obj))
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def assert_warns(warning_class, func, *args, **kw):
    """Test that a certain warning occurs.

    Parameters
    ----------
    warning_class : the warning class
        The class to test for, e.g. UserWarning.

    func : callable
        Calable object to trigger warnings.

    *args : the positional arguments to `func`.

    **kw : the keyword arguments to `func`

    Returns
    -------

    result : the return value of `func`

    """

    # very important to avoid uncontrolled state propagation
    clean_warning_registry()
    with warnings.catch_warnings(record=True) as w:
        # Cause all warnings to always be triggered.
        warnings.simplefilter("always")
        # Trigger a warning.
        result = func(*args, **kw)
        if hasattr(np, 'VisibleDeprecationWarning'):
            # Filter out numpy-specific warnings in numpy >= 1.9
            w = [e for e in w
                 if e.category is not np.VisibleDeprecationWarning]

        # Verify some things
        if not len(w) > 0:
            raise AssertionError("No warning raised when calling %s"
                                 % func.__name__)

        found = any(warning.category is warning_class for warning in w)
        if not found:
            raise AssertionError("%s did not give warning: %s( is %s)"
                                 % (func.__name__, warning_class, w))
    return result