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


Python warnings.simplefilter方法代码示例

本文整理汇总了Python中warnings.simplefilter方法的典型用法代码示例。如果您正苦于以下问题:Python warnings.simplefilter方法的具体用法?Python warnings.simplefilter怎么用?Python warnings.simplefilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在warnings的用法示例。


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

示例1: test_global_norm_clip

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_global_norm_clip():
    stypes = ['default', 'row_sparse']
    def check_global_norm_clip(stype, check_isfinite):
        x1 = mx.nd.ones((3,3)).tostype(stype)
        x2 = mx.nd.ones((4,4)).tostype(stype)
        norm = gluon.utils.clip_global_norm([x1, x2], 1.0, check_isfinite=check_isfinite)
        assert norm == 5.0
        assert_almost_equal(x1.asnumpy(), np.ones((3,3))/5)
        assert_almost_equal(x2.asnumpy(), np.ones((4,4))/5)

        x3 = mx.nd.array([1.0, 2.0, float('nan')]).tostype(stype)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            gluon.utils.clip_global_norm([x1, x3], 2.0, check_isfinite=check_isfinite)
            assert len(w) == check_isfinite

    for stype in stypes:
        for check_isfinite in [True, False]:
            check_global_norm_clip(stype, check_isfinite) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:21,代码来源:test_gluon.py

示例2: simple_moving_average

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def simple_moving_average(data, period):
    """
    Simple Moving Average.

    Formula:
    SUM(data / N)
    """
    check_for_period_error(data, period)
    # Mean of Empty Slice RuntimeWarning doesn't affect output so it is
    # supressed
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=RuntimeWarning)
        sma = list(map(
            lambda idx:
            np.mean(data[idx-(period-1):idx+1]),
            range(0, len(data))
            ))
    sma = fill_for_noncomputable_vals(data, sma)
    return sma 
开发者ID:kkuette,项目名称:TradzQAI,代码行数:21,代码来源:simple_moving_average.py

示例3: test_rmtree_test

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_rmtree_test(self):
        path = mkdtemp(self)
        utils.rmtree(path)
        self.assertFalse(exists(path))
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            utils.rmtree(path)
            self.assertFalse(w)

        utils.stub_item_attr_value(
            self, utils, 'rmtree_', utils.fake_error(IOError))
        path2 = mkdtemp(self)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            utils.rmtree(path2)
            self.assertIn("rmtree failed to remove", str(w[-1].message)) 
开发者ID:calmjs,项目名称:calmjs,代码行数:19,代码来源:test_testing.py

示例4: register_blueprint

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def register_blueprint(self, *args, **kwargs):
        """
        Proxy method provided for invoking the :func:`blueprint` method

        .. note::
            To be deprecated in 1.0. Use :func:`blueprint` instead.

        :param args: Blueprint object or (list, tuple) thereof
        :param kwargs: option dictionary with blueprint defaults
        :return: None
        """

        if self.debug:
            warnings.simplefilter("default")
        warnings.warn(
            "Use of register_blueprint will be deprecated in "
            "version 1.0.  Please use the blueprint method"
            " instead",
            DeprecationWarning,
        )
        return self.blueprint(*args, **kwargs) 
开发者ID:huge-success,项目名称:sanic,代码行数:23,代码来源:app.py

示例5: testAssertWarnsCallable

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def testAssertWarnsCallable(self):
        def _runtime_warn():
            warnings.warn("foo", RuntimeWarning)
        # Success when the right warning is triggered, even several times
        self.assertWarns(RuntimeWarning, _runtime_warn)
        self.assertWarns(RuntimeWarning, _runtime_warn)
        # A tuple of warning classes is accepted
        self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn)
        # *args and **kwargs also work
        self.assertWarns(RuntimeWarning,
                         warnings.warn, "foo", category=RuntimeWarning)
        # Failure when no warning is triggered
        with self.assertRaises(self.failureException):
            self.assertWarns(RuntimeWarning, lambda: 0)
        # Failure when another warning is triggered
        with warnings.catch_warnings():
            # Force default filter (in case tests are run with -We)
            warnings.simplefilter("default", RuntimeWarning)
            with self.assertRaises(self.failureException):
                self.assertWarns(DeprecationWarning, _runtime_warn)
        # Filters for other warnings are not modified
        with warnings.catch_warnings():
            warnings.simplefilter("error", RuntimeWarning)
            with self.assertRaises(RuntimeWarning):
                self.assertWarns(DeprecationWarning, _runtime_warn) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:test_case.py

示例6: test_import_star

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_import_star(self):
        """'import *' in nested functions."""
        # NICE_TO_HAVE
        codes = [
            func_gen(
                'func1',
                body=func_gen('func2', body='from math import *\nTrue')),
            func_gen(
                'func1',
                body='from math import *\n' + func_gen('func2', body='True')),
        ]
        sys.setrecursionlimit(1000)  # needed for weird PyPy versions
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", category=SyntaxWarning)
            for code in codes:
                self.throws(code, IMPORTSTAR)
        sys.setrecursionlimit(initial_recursion_limit) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:19,代码来源:didyoumean_sugg_tests.py

示例7: setUp

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def setUp(self):
        # Turn off numpy matrix warnings
        import warnings
        warnings.simplefilter('ignore', category=PendingDeprecationWarning)

        # Create a single input/single output linear system
        self.siso_linsys = ct.StateSpace(
            [[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[0]])

        # Create a multi input/multi output linear system
        self.mimo_linsys1 = ct.StateSpace(
            [[-1, 1], [0, -2]], [[1, 0], [0, 1]],
            [[1, 0], [0, 1]], np.zeros((2,2)))

        # Create a multi input/multi output linear system
        self.mimo_linsys2 = ct.StateSpace(
            [[-1, 1], [0, -2]], [[0, 1], [1, 0]],
            [[1, 0], [0, 1]], np.zeros((2,2)))

        # Create simulation parameters
        self.T = np.linspace(0, 10, 100)
        self.U = np.sin(self.T)
        self.X0 = [0, 0] 
开发者ID:python-control,项目名称:python-control,代码行数:25,代码来源:iosys_test.py

示例8: test_evalfr_deprecated

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_evalfr_deprecated(self):
        sys_tf = ct.tf([1], [1, 2, 1])
        frd_tf = FRD(sys_tf, np.logspace(-1, 1, 3))

        # Deprecated version of the call (should generate warning)
        import warnings
        with warnings.catch_warnings():
            # Make warnings generate an exception
            warnings.simplefilter('error')

            # Make sure that we get a pending deprecation warning
            self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.)

        # FRD.evalfr() is being deprecated
        import warnings
        with warnings.catch_warnings():
            # Make warnings generate an exception
            warnings.simplefilter('error')

            # Make sure that we get a pending deprecation warning
            self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.) 
开发者ID:python-control,项目名称:python-control,代码行数:23,代码来源:frd_test.py

示例9: test_filter_mempool_filter_address_and_payment_id

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_filter_mempool_filter_address_and_payment_id(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            # mempool excluded
            pmts = self.wallet.incoming(
                local_address='9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC',
                payment_id='03f6649304ea4cb2')
            self.assertEqual(len(pmts), 0)
            # mempool included
            pmts = self.wallet.incoming(
                unconfirmed=True,
                local_address='9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC',
                payment_id='03f6649304ea4cb2')
            self.assertEqual(len(pmts), 1)
            self.assertEqual(
                pmts[0].transaction.hash,
                'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c')
            self.assertEqual(len(w), 0) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:20,代码来源:test_wallet.py

示例10: test_filter_mempool_filter_txid

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_filter_mempool_filter_txid(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            # mempool excluded
            pmts = self.wallet.incoming(
                tx_id='d29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c')
            self.assertEqual(len(pmts), 0)
            # mempool included
            pmts = self.wallet.incoming(
                unconfirmed=True,
                tx_id='d29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c')
            self.assertEqual(len(pmts), 1)
            self.assertEqual(
                pmts[0].transaction.hash,
                'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c')
            self.assertEqual(len(w), 0) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:18,代码来源:test_wallet.py

示例11: _configure_logging

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def _configure_logging(level=logging.INFO):
    logging.addLevelName(logging.DEBUG, 'Debug:')
    logging.addLevelName(logging.INFO, 'Info:')
    logging.addLevelName(logging.WARNING, 'Warning!')
    logging.addLevelName(logging.CRITICAL, 'Critical!')
    logging.addLevelName(logging.ERROR, 'Error!')

    logging.basicConfig(format='%(levelname)s %(message)s', level=logging.INFO)

    if not sys.warnoptions:
        import warnings
        warnings.simplefilter("ignore")
        # TODO hack to get rid of deprecation warning that appeared allthough filters
        # are set to ignore. Is there a more sane way?
        warnings.warn = lambda *args, **kwargs: None 
开发者ID:mme,项目名称:vergeml,代码行数:17,代码来源:__main__.py

示例12: create

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def create(self):
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            self._legend = self._axes.legend(fontsize='small')
        if self._legend is not None:
            self._legend.get_frame().set_alpha(0.75)
            self._legend.set_visible(self._visible) 
开发者ID:EarToEarOak,项目名称:RF-Monitor,代码行数:9,代码来源:legend.py

示例13: get_translate

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def get_translate(workdir=None):

    filename = os.path.join(workdir, "Vicalloy/Fe-Co-V_140922a_META_DATA.csv")
    compdata_f = pd.read_csv(filename, sep="\t").dropna()
    print compdata_f.head()
    x = compdata_f["Xnom (mm)"].values
    y = compdata_f["Ynom (mm)"].values
    Co_concentration = compdata_f["Co (at%)"].values
    Fe_concentration = compdata_f["Fe (at%)"].values
    V_concentration = compdata_f["V (at%)"].values
    method = "linear"
    # method = 'nearest'

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        Co_concI = interp2d(x, y, Co_concentration, kind=method)
        Fe_concI = interp2d(x, y, Fe_concentration, kind=method)
        V_concI = interp2d(x, y, V_concentration, kind=method)

    def translate(key):
        manip_z, manip_y = key
        sample_y = manip_z - 69.5
        sample_x = (manip_y + 8) * 2
        Co = Co_concI(sample_x, sample_y)[0] / 100.0
        Fe = Fe_concI(sample_x, sample_y)[0] / 100.0
        V = V_concI(sample_x, sample_y)[0] / 100.0
        return ("Fe{:.2f}Co{:.2f}V{:.2f}".format(Fe, Co, V), sample_x, sample_y)

    return translate 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:31,代码来源:translate_vicalloy.py

示例14: test_translate_message_bad_translation

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_translate_message_bad_translation(self,
                                               mock_log,
                                               mock_translation):
        message_with_params = 'A message: %s'
        es_translation = 'A message in Spanish: %s %s'
        param = 'A Message param'

        translations = {message_with_params: es_translation}
        translator = fakes.FakeTranslations.translator({'es': translations})
        mock_translation.side_effect = translator

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            msg = _message.Message(message_with_params)
            msg = msg % param
            default_translation = message_with_params % param

            self.assertEqual(default_translation, msg.translation('es'))

            self.assertEqual(1, len(w))
            # Note(gibi): in python 3.4 str.__repr__ does not put the unicode
            # marker 'u' in front of the string representations so the test
            # removes that to have the same result in python 2.7 and 3.4
            self.assertEqual("Failed to insert replacement values into "
                             "translated message A message in Spanish: %s %s "
                             "(Original: 'A message: %s'): "
                             "not enough arguments for format string",
                             str(w[0].message).replace("u'", "'"))

        mock_log.debug.assert_called_with(('Failed to insert replacement '
                                           'values into translated message '
                                           '%s (Original: %r): %s'),
                                          es_translation,
                                          message_with_params,
                                          mock.ANY) 
开发者ID:openstack,项目名称:oslo.i18n,代码行数:37,代码来源:test_message.py

示例15: test_translate_message_bad_default_translation

# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import simplefilter [as 别名]
def test_translate_message_bad_default_translation(self,
                                                       mock_log,
                                                       mock_local,
                                                       mock_translation):
        message_with_params = 'A message: %s'
        es_translation = 'A message in Spanish: %s %s'
        param = 'A Message param'

        translations = {message_with_params: es_translation}
        translator = fakes.FakeTranslations.translator({'es': translations})
        mock_translation.side_effect = translator

        msg = _message.Message(message_with_params)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            msg = msg % param
            self.assertEqual(1, len(w))
            # Note(gibi): in python 3.4 str.__repr__ does not put the unicode
            # marker 'u' in front of the string representations so the test
            # removes that to have the same result in python 2.7 and 3.4
            self.assertEqual("Failed to insert replacement values into "
                             "translated message A message in Spanish: %s %s "
                             "(Original: 'A message: %s'): "
                             "not enough arguments for format string",
                             str(w[0].message).replace("u'", "'"))

        mock_log.debug.assert_called_with(('Failed to insert replacement '
                                           'values into translated message '
                                           '%s (Original: %r): %s'),
                                          es_translation,
                                          message_with_params,
                                          mock.ANY)
        mock_log.reset_mock()

        default_translation = message_with_params % param
        self.assertEqual(default_translation, msg)
        self.assertFalse(mock_log.warning.called) 
开发者ID:openstack,项目名称:oslo.i18n,代码行数:40,代码来源:test_message.py


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