当前位置: 首页>>代码示例>>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;未经允许,请勿转载。