<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
df = pd.DataFrame({'x': [1, 2, 3], 'y': [2, 3, 4]})
df.eval('(x - y)').std() # evaluates
df.eval('(x - y).std()') # exception: AttributeError: 'BinOp' object has no attribute 'value'
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'x'</span>: [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>], <span class="pl-s">'y'</span>: [<span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>]})
<span class="pl-s1">df</span>.<span class="pl-en">eval</span>(<span class="pl-s">'(x - y)'</span>).<span class="pl-en">std</span>() <span class="pl-c"># evaluates</span>
<span class="pl-s1">df</span>.<span class="pl-en">eval</span>(<span class="pl-s">'(x - y).std()'</span>) <span class="pl-c"># exception: AttributeError: 'BinOp' object has no attribute 'value'</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">I expected this type of <code class="notranslate">eval()</code> expression to work correctly. I'm not sure how to justify the behavior other than it being more intuitive and practical.</p>
<p dir="auto">I searched and was able to find similar errors, but the cause seems to be with <code class="notranslate">UnaryOp</code> instead of <code class="notranslate">BinOp</code>:</p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="228886728" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/16363" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/16363/hovercard" href="https://github.com/pandas-dev/pandas/issues/16363">#16363</a></li>
</ul>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt; df = pd.DataFrame({'x': [1, 2, 3], 'y': [2, 3, 4]})
&gt;&gt;&gt; df.eval('(x - y)').std() # evaluates
0.0
&gt;&gt;&gt; df.eval('(x - y).std()') # should also evaluate
0.0"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'x'</span>: [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>], <span class="pl-s">'y'</span>: [<span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>]})
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-en">eval</span>(<span class="pl-s">'(x - y)'</span>).<span class="pl-en">std</span>() <span class="pl-c"># evaluates</span>
<span class="pl-c1">0.0</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-en">eval</span>(<span class="pl-s">'(x - y).std()'</span>) <span class="pl-c"># should also evaluate</span>
<span class="pl-c1">0.0</span></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.3.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.13.0-32-generic<br>
machine: x86_64<br>
processor: x86_64<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_US.UTF-8<br>
LOCALE: en_US.UTF-8</p>
<p dir="auto">pandas: 0.22.0<br>
pytest: None<br>
pip: 9.0.1<br>
setuptools: 32.3.1<br>
Cython: None<br>
numpy: 1.14.0<br>
scipy: None<br>
pyarrow: None<br>
xarray: None<br>
IPython: None<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.1<br>
pytz: 2017.3<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.2.0<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.2.2<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def test_unary():
    df = pd.DataFrame({'x': np.array([0.11, 0], dtype=np.float32)})
    res = df.eval('(x &gt; 0.1) | (x &lt; -0.1)')
    assert np.array_equal(res, np.array([True, False])), res"><pre class="notranslate"><code class="notranslate">def test_unary():
    df = pd.DataFrame({'x': np.array([0.11, 0], dtype=np.float32)})
    res = df.eval('(x &gt; 0.1) | (x &lt; -0.1)')
    assert np.array_equal(res, np.array([True, False])), res
</code></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">This is related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="109686658" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/11235" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/11235/hovercard" href="https://github.com/pandas-dev/pandas/issues/11235">#11235</a>.<br>
on python 3.6, pandas 20.1, this raises an error the traceback ends with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  File &quot;.../envs/py3/lib/python3.6/site-packages/pandas/core/computation/expr.py&quot;, line 370, in _maybe_downcast_constants
    name = self.env.add_tmp(np.float32(right.value))
AttributeError: 'UnaryOp' object has no attribute 'value'"><pre class="notranslate"><code class="notranslate">  File ".../envs/py3/lib/python3.6/site-packages/pandas/core/computation/expr.py", line 370, in _maybe_downcast_constants
    name = self.env.add_tmp(np.float32(right.value))
AttributeError: 'UnaryOp' object has no attribute 'value'
</code></pre></div>
<p dir="auto">In that case the right is -(0.1)</p>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-49-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
<p dir="auto">pandas: 0.20.1<br>
pytest: None<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.12.1<br>
scipy: 0.19.0<br>
xarray: None<br>
IPython: 6.0.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">Another example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; df = pd.DataFrame({'x':[1,2,3,4,5]})
&gt;&gt;&gt; df.eval('x.shift(-1)')"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'x'</span>:[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>]})
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-en">eval</span>(<span class="pl-s">'x.shift(-1)'</span>)</pre></div>