From 3fca158552f09ca2e778fafd2b8235bb403e5c6a Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Sat, 21 Sep 2013 16:44:04 -0400 Subject: [PATCH] DOC: show disallowed/allowed eval syntax --- doc/source/enhancingperf.rst | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doc/source/enhancingperf.rst b/doc/source/enhancingperf.rst index bade382f03c59..e59cb6ac30964 100644 --- a/doc/source/enhancingperf.rst +++ b/doc/source/enhancingperf.rst @@ -330,6 +330,42 @@ engine in addition to some extensions available only in pandas. The larger the frame and the larger the expression the more speedup you will see from using :func:`~pandas.eval`. +Supported Syntax +~~~~~~~~~~~~~~~~ + +These operations are supported by :func:`~pandas.eval`: + +- Arithmetic operations except for the left shift (``<<``) and right shift + (``>>``) operators, e.g., ``df + 2 * pi / s ** 4 % 42 - the_golden_ratio`` +- Comparison operations, e.g., ``2 < df < df2`` +- Boolean operations, e.g., ``df < df2 and df3 < df4 or not df_bool`` +- ``list`` and ``tuple`` literals, e.g., ``[1, 2]`` or ``(1, 2)`` +- Attribute access, e.g., ``df.a`` +- Subscript expressions, e.g., ``df[0]`` +- Simple variable evaluation, e.g., ``pd.eval('df')`` (this is not very useful) + +This Python syntax is **not** allowed: + +* Expressions + + - Function calls + - ``is``/``is not`` operations + - ``if`` expressions + - ``lambda`` expressions + - ``list``/``set``/``dict`` comprehensions + - Literal ``dict`` and ``set`` expressions + - ``yield`` expressions + - Generator expressions + - Boolean expressions consisting of only scalar values + +* Statements + + - Neither `simple `__ + nor `compound `__ + statements are allowed. This includes things like ``for``, ``while``, and + ``if``. + + :func:`~pandas.eval` Examples ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~