Skip to content

Commit 16e2f63

Browse files
committed
Merge pull request #4922 from cpcloud/eval-syntax-docs
DOC: show disallowed eval syntax
2 parents cdba224 + 3fca158 commit 16e2f63

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

doc/source/enhancingperf.rst

+36
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,42 @@ engine in addition to some extensions available only in pandas.
330330
The larger the frame and the larger the expression the more speedup you will
331331
see from using :func:`~pandas.eval`.
332332

333+
Supported Syntax
334+
~~~~~~~~~~~~~~~~
335+
336+
These operations are supported by :func:`~pandas.eval`:
337+
338+
- Arithmetic operations except for the left shift (``<<``) and right shift
339+
(``>>``) operators, e.g., ``df + 2 * pi / s ** 4 % 42 - the_golden_ratio``
340+
- Comparison operations, e.g., ``2 < df < df2``
341+
- Boolean operations, e.g., ``df < df2 and df3 < df4 or not df_bool``
342+
- ``list`` and ``tuple`` literals, e.g., ``[1, 2]`` or ``(1, 2)``
343+
- Attribute access, e.g., ``df.a``
344+
- Subscript expressions, e.g., ``df[0]``
345+
- Simple variable evaluation, e.g., ``pd.eval('df')`` (this is not very useful)
346+
347+
This Python syntax is **not** allowed:
348+
349+
* Expressions
350+
351+
- Function calls
352+
- ``is``/``is not`` operations
353+
- ``if`` expressions
354+
- ``lambda`` expressions
355+
- ``list``/``set``/``dict`` comprehensions
356+
- Literal ``dict`` and ``set`` expressions
357+
- ``yield`` expressions
358+
- Generator expressions
359+
- Boolean expressions consisting of only scalar values
360+
361+
* Statements
362+
363+
- Neither `simple <http://docs.python.org/2/reference/simple_stmts.html>`__
364+
nor `compound <http://docs.python.org/2/reference/compound_stmts.html>`__
365+
statements are allowed. This includes things like ``for``, ``while``, and
366+
``if``.
367+
368+
333369

334370
:func:`~pandas.eval` Examples
335371
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)