BUG: Fix #16363 - Prevent visit_BinOp from accessing value on UnaryOp
State: closed

- [x] closes #16363
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Checking `hasattr(side, 'value')` resolves the bug and is consistent with the way that other methods of the `BaseExprVisitor` class work (e.g., both `visit_Call_35` and `visit_Call_legacy` check for 'value').

Labels:
name: Bug
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=h1) Report
> Merging [#25928](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1d4c89f4d747854def6c32733383b4afa250165d?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25928/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25928      +/-   ##
==========================================
- Coverage    91.8%   91.79%   -0.01%     
==========================================
  Files         174      174              
  Lines       52536    52536              
==========================================
- Hits        48231    48226       -5     
- Misses       4305     4310       +5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.35% <100%> (ø)` | :arrow_up: |
| #single | `41.88% <100%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `88.52% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `75% <0%> (-12.5%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.63% <0%> (-0.11%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=footer). Last update [1d4c89f...ef777e7](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=h1) Report
> Merging [#25928](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1d4c89f4d747854def6c32733383b4afa250165d?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25928/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25928      +/-   ##
==========================================
- Coverage    91.8%    91.8%   -0.01%     
==========================================
  Files         174      175       +1     
  Lines       52536    52578      +42     
==========================================
+ Hits        48231    48269      +38     
- Misses       4305     4309       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.36% <100%> (ø)` | :arrow_up: |
| #single | `41.9% <100%> (-0.05%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `88.52% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `75% <0%> (-12.5%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.63% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/dtypes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Jhc2UucHk=) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/groupby/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9iYXNlLnB5) | `91.83% <0%> (ø)` | :arrow_up: |
| [pandas/core/arrays/array\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2FycmF5Xy5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/io/gcs.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2djcy5weQ==) | `80% <0%> (ø)` | :arrow_up: |
| [pandas/core/groupby/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9ncm91cGJ5LnB5) | `97.21% <0%> (ø)` | :arrow_up: |
| [pandas/core/internals/managers.py](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL21hbmFnZXJzLnB5) | `93.93% <0%> (ø)` | :arrow_up: |
| ... and [15 more](https://codecov.io/gh/pandas-dev/pandas/pull/25928/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=footer). Last update [1d4c89f...1b88337](https://codecov.io/gh/pandas-dev/pandas/pull/25928?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jreback Should be ready for another review.
thanks @alexcwatt 
@jreback & @alexcwatt - this was also an issue for string data, as I showed in this previous comment on #16363 :

https://github.com/pandas-dev/pandas/issues/16363#issuecomment-313231698

The test case is:

```
def test_unary():
    df = pd.DataFrame({'x': ["one", "two"]})
    df.eval('x.shift(-1)')
```

Is that also fixed now?  If not, we should keep #16363 open as not fixed.
you can test on master and if not pls open. new issue 

if it works then can add an additional test (pls do a PR)
I don't think I'll have time for that very soon, I'd recommend just re-opening #16363 until the full set of problems identified in the ticket can be verified as fixed.
plan make a new issue instead