當前位置: 首頁>>代碼示例>>Python>>正文


Python ops.UndefinedVariableError方法代碼示例

本文整理匯總了Python中pandas.core.computation.ops.UndefinedVariableError方法的典型用法代碼示例。如果您正苦於以下問題:Python ops.UndefinedVariableError方法的具體用法?Python ops.UndefinedVariableError怎麽用?Python ops.UndefinedVariableError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.core.computation.ops的用法示例。


在下文中一共展示了ops.UndefinedVariableError方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_query_scope

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_query_scope(self):
        from pandas.core.computation.ops import UndefinedVariableError
        engine, parser = self.engine, self.parser
        skip_if_no_pandas_parser(parser)

        df = DataFrame(np.random.randn(20, 2), columns=list('ab'))

        a, b = 1, 2  # noqa
        res = df.query('a > b', engine=engine, parser=parser)
        expected = df[df.a > df.b]
        assert_frame_equal(res, expected)

        res = df.query('@a > b', engine=engine, parser=parser)
        expected = df[a > df.b]
        assert_frame_equal(res, expected)

        # no local variable c
        with pytest.raises(UndefinedVariableError):
            df.query('@a > b > @c', engine=engine, parser=parser)

        # no column named 'c'
        with pytest.raises(UndefinedVariableError):
            df.query('@a > b > c', engine=engine, parser=parser) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_query_eval.py

示例2: test_query_doesnt_pickup_local

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_query_doesnt_pickup_local(self):
        from pandas.core.computation.ops import UndefinedVariableError

        engine, parser = self.engine, self.parser
        n = m = 10
        df = DataFrame(np.random.randint(m, size=(n, 3)), columns=list('abc'))

        # we don't pick up the local 'sin'
        with pytest.raises(UndefinedVariableError):
            df.query('sin > 5', engine=engine, parser=parser) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_query_eval.py

示例3: test_nested_raises_on_local_self_reference

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_nested_raises_on_local_self_reference(self):
        from pandas.core.computation.ops import UndefinedVariableError

        df = DataFrame(np.random.randn(5, 3))

        # can't reference ourself b/c we're a local so @ is necessary
        with pytest.raises(UndefinedVariableError):
            df.query('df > 0', engine=self.engine, parser=self.parser) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_query_eval.py

示例4: test_query_undefined_local

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_query_undefined_local(self):
        from pandas.core.computation.ops import UndefinedVariableError
        engine, parser = self.engine, self.parser
        skip_if_no_pandas_parser(parser)

        df = DataFrame(np.random.rand(10, 2), columns=list('ab'))
        msg = "local variable 'c' is not defined"

        with pytest.raises(UndefinedVariableError, match=msg):
            df.query('a == @c', engine=engine, parser=parser) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_query_eval.py

示例5: test_nested_scope

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_nested_scope(self):
        from pandas.core.computation.ops import UndefinedVariableError
        engine = self.engine
        parser = self.parser
        # smoke test
        x = 1  # noqa
        result = pd.eval('x + 1', engine=engine, parser=parser)
        assert result == 2

        df = DataFrame(np.random.randn(5, 3))
        df2 = DataFrame(np.random.randn(5, 3))

        # don't have the pandas parser
        with pytest.raises(SyntaxError):
            df.query('(@df>0) & (@df2>0)', engine=engine, parser=parser)

        with pytest.raises(UndefinedVariableError):
            df.query('(df>0) & (df2>0)', engine=engine, parser=parser)

        expected = df[(df > 0) & (df2 > 0)]
        result = pd.eval('df[(df > 0) & (df2 > 0)]', engine=engine,
                         parser=parser)
        assert_frame_equal(expected, result)

        expected = df[(df > 0) & (df2 > 0) & (df[df > 0] > 0)]
        result = pd.eval('df[(df > 0) & (df2 > 0) & (df[df > 0] > 0)]',
                         engine=engine, parser=parser)
        assert_frame_equal(expected, result) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:30,代碼來源:test_query_eval.py

示例6: test_query_undefined_local

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_query_undefined_local(self):
        from pandas.core.computation.ops import UndefinedVariableError
        engine, parser = self.engine, self.parser
        skip_if_no_pandas_parser(parser)
        df = DataFrame(np.random.rand(10, 2), columns=list('ab'))
        with tm.assert_raises_regex(UndefinedVariableError,
                                    "local variable 'c' is not defined"):
            df.query('a == @c', engine=engine, parser=parser) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:test_query_eval.py

示例7: visit_Assign

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def visit_Assign(self, node, **kwargs):
        """
        support a single assignment node, like

        c = a + b

        set the assigner at the top level, must be a Name node which
        might or might not exist in the resolvers

        """

        if len(node.targets) != 1:
            raise SyntaxError('can only assign a single expression')
        if not isinstance(node.targets[0], ast.Name):
            raise SyntaxError('left hand side of an assignment must be a '
                              'single name')
        if self.env.target is None:
            raise ValueError('cannot assign without a target object')

        try:
            assigner = self.visit(node.targets[0], **kwargs)
        except UndefinedVariableError:
            assigner = node.targets[0].id

        self.assigner = getattr(assigner, 'name', assigner)
        if self.assigner is None:
            raise SyntaxError('left hand side of an assignment must be a '
                              'single resolvable name')

        return self.visit(node.value, **kwargs) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:32,代碼來源:expr.py

示例8: test_filter_rows_catches_illegal

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def test_filter_rows_catches_illegal():
    df = pd.DataFrame(list(np.ndindex((10, 2))), columns=["Tag  1", "Tag 2"])
    with pytest.raises(UndefinedVariableError):
        pandas_filter_rows(df, "sys.exit(0)")
    with pytest.raises(NotImplementedError):
        pandas_filter_rows(df, "lambda x:x")
    with pytest.raises(ValueError):
        pandas_filter_rows(df, "__import__('os').system('clear')"), ValueError 
開發者ID:equinor,項目名稱:gordo,代碼行數:10,代碼來源:test_filter_rows.py

示例9: _resolve_name

# 需要導入模塊: from pandas.core.computation import ops [as 別名]
# 或者: from pandas.core.computation.ops import UndefinedVariableError [as 別名]
def _resolve_name(self):
        # must be a queryables
        if self.side == 'left':
            if self.name not in self.env.queryables:
                raise NameError('name {name!r} is not defined'
                                .format(name=self.name))
            return self.name

        # resolve the rhs (and allow it to be None)
        try:
            return self.env.resolve(self.name, is_local=False)
        except UndefinedVariableError:
            return self.name 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:15,代碼來源:pytables.py


注:本文中的pandas.core.computation.ops.UndefinedVariableError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。