当前位置: 首页>>代码示例>>Python>>正文


Python utils.WarningManager类代码示例

本文整理汇总了Python中numpy.testing.utils.WarningManager的典型用法代码示例。如果您正苦于以下问题:Python WarningManager类的具体用法?Python WarningManager怎么用?Python WarningManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WarningManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cs_graph_components

def test_cs_graph_components():
    D = np.eye(4, dtype=np.bool)

    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        warnings.filterwarnings("ignore",
                    message="`cs_graph_components` is deprecated")

        n_comp, flag = csgraph.cs_graph_components(csr_matrix(D))
        assert_(n_comp == 4)
        assert_equal(flag, [0, 1, 2, 3])

        D[0, 1] = D[1, 0] = 1

        n_comp, flag = csgraph.cs_graph_components(csr_matrix(D))
        assert_(n_comp == 3)
        assert_equal(flag, [0, 0, 1, 2])

        # A pathological case...
        D[2, 2] = 0
        n_comp, flag = csgraph.cs_graph_components(csr_matrix(D))
        assert_(n_comp == 2)
        assert_equal(flag, [0, 0, -2, 1])
    finally:
        warn_ctx.__exit__()
开发者ID:317070,项目名称:scipy,代码行数:26,代码来源:test_graph_components.py

示例2: test_arrays_replicated_3d

    def test_arrays_replicated_3d(self):
        warn_ctx = WarningManager()
        warn_ctx.__enter__()
        try:
            warnings.filterwarnings('ignore', message="warning: multi-dimensional structures")
            s = readsav(path.join(DATA_PATH, 'struct_pointer_arrays_replicated_3d.sav'), verbose=False)
        finally:
            warn_ctx.__exit__()

        # Check column types
        assert_true(s.arrays_rep.g.dtype.type is np.object_)
        assert_true(s.arrays_rep.h.dtype.type is np.object_)

        # Check column shapes
        assert_equal(s.arrays_rep.g.shape, (4, 3, 2))
        assert_equal(s.arrays_rep.h.shape, (4, 3, 2))

        # Check values
        for i in range(4):
            for j in range(3):
                for k in range(2):
                    assert_array_identical(s.arrays_rep.g[i, j, k], np.repeat(np.float32(4.), 2).astype(np.object_))
                    assert_array_identical(s.arrays_rep.h[i, j, k], np.repeat(np.float32(4.), 3).astype(np.object_))
                    assert_true(np.all(vect_id(s.arrays_rep.g[i, j, k]) == id(s.arrays_rep.g[0, 0, 0][0])))
                    assert_true(np.all(vect_id(s.arrays_rep.h[i, j, k]) == id(s.arrays_rep.h[0, 0, 0][0])))
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:25,代码来源:test_idl.py

示例3: test_ksone_fit_freeze

def test_ksone_fit_freeze():
    """Regression test for ticket #1638.

    """
    d = np.array(
        [-0.18879233,  0.15734249,  0.18695107,  0.27908787, -0.248649,
         -0.2171497 ,  0.12233512,  0.15126419,  0.03119282,  0.4365294 ,
          0.08930393, -0.23509903,  0.28231224, -0.09974875, -0.25196048,
          0.11102028,  0.1427649 ,  0.10176452,  0.18754054,  0.25826724,
          0.05988819,  0.0531668 ,  0.21906056,  0.32106729,  0.2117662 ,
          0.10886442,  0.09375789,  0.24583286, -0.22968366, -0.07842391,
         -0.31195432, -0.21271196,  0.1114243 , -0.13293002,  0.01331725,
         -0.04330977, -0.09485776, -0.28434547,  0.22245721, -0.18518199,
         -0.10943985, -0.35243174,  0.06897665, -0.03553363, -0.0701746 ,
         -0.06037974,  0.37670779, -0.21684405])

    olderr = np.seterr(invalid='ignore')
    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        warnings.simplefilter('ignore', UserWarning)
        stats.ksone.fit(d)
    finally:
        warn_ctx.__exit__()
        np.seterr(**olderr)
开发者ID:ambidextrousTx,项目名称:scipy,代码行数:25,代码来源:test_distributions.py

示例4: test_find

def test_find():
    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        warnings.simplefilter('ignore', DeprecationWarning)

        keys = find('weak mixing', disp=False)
        assert_equal(keys, ['weak mixing angle'])

        keys = find('qwertyuiop', disp=False)
        assert_equal(keys, [])

        keys = find('natural unit', disp=False)
        assert_equal(keys, sorted(['natural unit of velocity',
                                    'natural unit of action',
                                    'natural unit of action in eV s',
                                    'natural unit of mass',
                                    'natural unit of energy',
                                    'natural unit of energy in MeV',
                                    'natural unit of mom.um',
                                    'natural unit of mom.um in MeV/c',
                                    'natural unit of length',
                                    'natural unit of time']))
    finally:
        warn_ctx.__exit__()
开发者ID:87,项目名称:scipy,代码行数:25,代码来源:test_codata.py

示例5: test_integral

    def test_integral(self):
        x = [1,1,1,2,2,2,4,4,4]
        y = [1,2,3,1,2,3,1,2,3]
        z = array([0,7,8,3,4,7,1,3,4])

        warn_ctx = WarningManager()
        warn_ctx.__enter__()
        try:
            # This seems to fail (ier=1, see ticket 1642).
            warnings.simplefilter('ignore', UserWarning)
            lut = SmoothBivariateSpline(x, y, z, kx=1, ky=1, s=0)
        finally:
            warn_ctx.__exit__()

        tx = [1,2,4]
        ty = [1,2,3]

        tz = lut(tx, ty)
        trpz = .25*(diff(tx)[:,None]*diff(ty)[None,:]
                    * (tz[:-1,:-1]+tz[1:,:-1]+tz[:-1,1:]+tz[1:,1:])).sum()
        assert_almost_equal(lut.integral(tx[0], tx[-1], ty[0], ty[-1]), trpz)

        lut2 = SmoothBivariateSpline(x, y, z, kx=2, ky=2, s=0)
        assert_almost_equal(lut2.integral(tx[0], tx[-1], ty[0], ty[-1]), trpz,
                            decimal=0)  # the quadratures give 23.75 and 23.85

        tz = lut(tx[:-1], ty[:-1])
        trpz = .25*(diff(tx[:-1])[:,None]*diff(ty[:-1])[None,:]
                    * (tz[:-1,:-1]+tz[1:,:-1]+tz[:-1,1:]+tz[1:,1:])).sum()
        assert_almost_equal(lut.integral(tx[0], tx[-2], ty[0], ty[-2]), trpz)
开发者ID:NelleV,项目名称:scipy,代码行数:30,代码来源:test_fitpack2.py

示例6: test_bilinearity

    def test_bilinearity(self):
        x = [1,1,1,2,2,2,3,3,3]
        y = [1,2,3,1,2,3,1,2,3]
        z = [0,7,8,3,4,7,1,3,4]
        s = 0.1
        tx = [1+s,3-s]
        ty = [1+s,3-s]
        warn_ctx = WarningManager()
        warn_ctx.__enter__()
        try:
            # This seems to fail (ier=1, see ticket 1642).
            warnings.simplefilter('ignore', UserWarning)
            lut = LSQBivariateSpline(x,y,z,tx,ty,kx=1,ky=1)
        finally:
            warn_ctx.__exit__()

        tx, ty = lut.get_knots()

        for xa, xb in zip(tx[:-1], tx[1:]):
            for ya, yb in zip(ty[:-1], ty[1:]):
                for t in [0.1, 0.5, 0.9]:
                    for s in [0.3, 0.4, 0.7]:
                        xp = xa*(1-t) + xb*t
                        yp = ya*(1-s) + yb*s
                        zp = (+ lut(xa, ya)*(1-t)*(1-s)
                              + lut(xb, ya)*t*(1-s)
                              + lut(xa, yb)*(1-t)*s
                              + lut(xb, yb)*t*s)
                        assert_almost_equal(lut(xp,yp), zp)
开发者ID:NelleV,项目名称:scipy,代码行数:29,代码来源:test_fitpack2.py

示例7: test_array_maskna_astype

def test_array_maskna_astype():
    dtsrc = [np.dtype(d) for d in '?bhilqpBHILQPefdgFDGSUO']
    #dtsrc.append(np.dtype([('b', np.int, (1,))]))
    dtsrc.append(np.dtype('datetime64[D]'))
    dtsrc.append(np.dtype('timedelta64[s]'))

    dtdst = [np.dtype(d) for d in '?bhilqpBHILQPefdgFDGSUO']
    #dtdst.append(np.dtype([('b', np.int, (1,))]))
    dtdst.append(np.dtype('datetime64[D]'))
    dtdst.append(np.dtype('timedelta64[s]'))

    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        warnings.simplefilter("ignore", np.ComplexWarning)
        for dt1 in dtsrc:
            a = np.ones(2, dt1, maskna=1)
            a[1] = np.NA
            for dt2 in dtdst:
                msg = 'type %s to %s conversion' % (dt1, dt2)
                b = a.astype(dt2)
                assert_(b.flags.maskna, msg)
                assert_(b.flags.ownmaskna, msg)
                assert_(np.isna(b[1]), msg)
    finally:
        warn_ctx.__exit__()
开发者ID:ejmvar,项目名称:numpy,代码行数:26,代码来源:test_maskna.py

示例8: test_1d_shape

def test_1d_shape():
    # Current 5 behavior is 1D -> column vector
    arr = np.arange(5)
    stream = BytesIO()
    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        # silence warnings for tests
        warnings.simplefilter('ignore')
        savemat(stream, {'oned':arr}, format='5')
        vals = loadmat(stream)
        assert_equal(vals['oned'].shape, (5,1))
        # Current 4 behavior is 1D -> row vector
        stream = BytesIO()
        savemat(stream, {'oned':arr}, format='4')
        vals = loadmat(stream)
        assert_equal(vals['oned'].shape, (1, 5))
        for format in ('4', '5'):
            # can be explicitly 'column' for oned_as
            stream = BytesIO()
            savemat(stream, {'oned':arr},
                    format=format,
                    oned_as='column')
            vals = loadmat(stream)
            assert_equal(vals['oned'].shape, (5,1))
            # but different from 'row'
            stream = BytesIO()
            savemat(stream, {'oned':arr},
                    format=format,
                    oned_as='row')
            vals = loadmat(stream)
            assert_equal(vals['oned'].shape, (1,5))
    finally:
        warn_ctx.__exit__()
开发者ID:ahojnnes,项目名称:scipy,代码行数:34,代码来源:test_mio.py

示例9: setUp

class _DeprecationAccept:
    def setUp(self):
        self.mgr = WarningManager()
        self.mgr.__enter__()
        warnings.simplefilter("ignore", DeprecationWarning)

    def tearDown(self):
        self.mgr.__exit__()
开发者ID:AkshayaDeviGanesh,项目名称:scipy,代码行数:8,代码来源:test_umfpack.py

示例10: test_complex_scalar_warning

 def test_complex_scalar_warning(self):
     for tp in [np.csingle, np.cdouble, np.clongdouble]:
         x = tp(1+2j)
         assert_warns(np.ComplexWarning, float, x)
         ctx = WarningManager()
         ctx.__enter__()
         warnings.simplefilter('ignore')
         assert_equal(float(x), float(x.real))
         ctx.__exit__()
开发者ID:eteq,项目名称:numpy,代码行数:9,代码来源:test_regression.py

示例11: test_summary

 def test_summary(self):
     # smoke test
     warn_ctx = WarningManager()
     warn_ctx.__enter__()
     try:
         warnings.filterwarnings("ignore",
                                 "kurtosistest only valid for n>=20")
         summary = self.model.fit().summary()
     finally:
         warn_ctx.__exit__()
开发者ID:Code-fish,项目名称:statsmodels,代码行数:10,代码来源:test_formula.py

示例12: test_read_1

def test_read_1():
    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        warnings.simplefilter('ignore', wavfile.WavFileWarning)
        rate, data = wavfile.read(datafile('test-44100-le-1ch-4bytes.wav'))
    finally:
        warn_ctx.__exit__()

    assert_equal(rate, 44100)
    assert_(np.issubdtype(data.dtype, np.int32))
    assert_equal(data.shape, (4410,))
开发者ID:87,项目名称:scipy,代码行数:12,代码来源:test_wavfile.py

示例13: test_set_fields

 def test_set_fields(self):
     "Tests setting fields."
     base = self.base.copy()
     mbase = base.view(mrecarray)
     mbase = mbase.copy()
     mbase.fill_value = (999999,1e20,'N/A')
     # Change the data, the mask should be conserved
     mbase.a._data[:] = 5
     assert_equal(mbase['a']._data, [5,5,5,5,5])
     assert_equal(mbase['a']._mask, [0,1,0,0,1])
     # Change the elements, and the mask will follow
     mbase.a = 1
     assert_equal(mbase['a']._data, [1]*5)
     assert_equal(ma.getmaskarray(mbase['a']), [0]*5)
     # Use to be _mask, now it's recordmask
     assert_equal(mbase.recordmask, [False]*5)
     assert_equal(mbase._mask.tolist(),
                  np.array([(0,0,0),(0,1,1),(0,0,0),(0,0,0),(0,1,1)],
                           dtype=bool))
     # Set a field to mask ........................
     mbase.c = masked
     # Use to be mask, and now it's still mask !
     assert_equal(mbase.c.mask, [1]*5)
     assert_equal(mbase.c.recordmask, [1]*5)
     assert_equal(ma.getmaskarray(mbase['c']), [1]*5)
     assert_equal(ma.getdata(mbase['c']), [asbytes('N/A')]*5)
     assert_equal(mbase._mask.tolist(),
                  np.array([(0,0,1),(0,1,1),(0,0,1),(0,0,1),(0,1,1)],
                           dtype=bool))
     # Set fields by slices .......................
     mbase = base.view(mrecarray).copy()
     mbase.a[3:] = 5
     assert_equal(mbase.a, [1,2,3,5,5])
     assert_equal(mbase.a._mask, [0,1,0,0,0])
     mbase.b[3:] = masked
     assert_equal(mbase.b, base['b'])
     assert_equal(mbase.b._mask, [0,1,0,1,1])
     # Set fields globally..........................
     ndtype = [('alpha','|S1'),('num',int)]
     data = ma.array([('a',1),('b',2),('c',3)], dtype=ndtype)
     rdata = data.view(MaskedRecords)
     val = ma.array([10,20,30], mask=[1,0,0])
     #
     warn_ctx = WarningManager()
     warn_ctx.__enter__()
     try:
         warnings.simplefilter("ignore")
         rdata['num'] = val
         assert_equal(rdata.num, val)
         assert_equal(rdata.num.mask, [1,0,0])
     finally:
         warn_ctx.__exit__()
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:52,代码来源:test_mrecords.py

示例14: test_warnings

def test_warnings():
    fname = pjoin(test_data_path, 'testdouble_7.1_GLNX86.mat')
    warn_ctx = WarningManager()
    warn_ctx.__enter__()
    try:
        warnings.simplefilter('error')
        # This should not generate a warning
        mres = loadmat(fname, struct_as_record=True)
        # This neither
        mres = loadmat(fname, struct_as_record=False)
        # This should - because of deprecated system path search
        assert_raises(DeprecationWarning, find_mat_file, fname)
    finally:
        warn_ctx.__exit__()
开发者ID:ahojnnes,项目名称:scipy,代码行数:14,代码来源:test_mio.py

示例15: test_blas

    def test_blas(self):
        a = array([[1,1,1]])
        b = array([[1],[1],[1]])

        # get_blas_funcs is deprecated, silence the warning
        warn_ctx = WarningManager()
        warn_ctx.__enter__()
        try:
            warnings.simplefilter('ignore', DeprecationWarning)
            gemm, = get_blas_funcs(('gemm',),(a,b))
        finally:
            warn_ctx.__exit__()

        assert_array_almost_equal(gemm(1,a,b),[[3]],15)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:14,代码来源:test_blas.py


注:本文中的numpy.testing.utils.WarningManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。