BUG: fix calling local references with keyword arguments in query
State: closed

- [ ] closes #xxxx
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

calling local references with keyword arguments in query fails with attribute error:

```python
import numpy as np
import pandas as pd

def f(a, b):
    return b

df = pd.DataFrame()

df['val'] = np.arange(10)
print(df.query('val > @f(4, 5)'))
print(df.query('val > @f(4, b=5)'))
```

```
   val
6    6
7    7
8    8
9    9
Traceback (most recent call last):

  File "C:/Users/uidn3651/Desktop/untitled0.py", line 10, in <module>
    print(df.query('val > @f(4, b=5)'))

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\frame.py", line 3052, in query
    res = self.eval(expr, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\frame.py", line 3169, in eval
    return _eval(expr, inplace=inplace, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\eval.py", line 293, in eval
    truediv=truediv)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 749, in __init__
    self.terms = self.parse()

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 766, in parse
    return self._visitor.visit(self.expr)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 370, in visit
    return visitor(node, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 376, in visit_Module
    return self.visit(expr, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 370, in visit
    return visitor(node, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 379, in visit_Expr
    return self.visit(node.value, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 370, in visit
    return visitor(node, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 674, in visit_Compare
    return self.visit(binop)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 370, in visit
    return visitor(node, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 476, in visit_BinOp
    op, op_class, left, right = self._maybe_transform_eq_ne(node)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 413, in _maybe_transform_eq_ne
    right = self.visit(node.right, side='right')

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 370, in visit
    return visitor(node, **kwargs)

  File "d:\work\02__pythonworkspace\_venv\lib\site-packages\pandas\core\computation\expr.py", line 657, in visit_Call
    kwargs.append(ast.keyword(

AttributeError: 'dict' object has no attribute 'append'
```

With the fix this works correctly

```
   val
6    6
7    7
8    8
9    9
   val
6    6
7    7
8    8
9    9
```


Labels:
name: Algos
description: Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26426?src=pr&el=h1) Report
> Merging [#26426](https://codecov.io/gh/pandas-dev/pandas/pull/26426?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f44ac0634efa9948dbafeb5fb68e60c5e4e44f76?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/26426/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26426?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26426      +/-   ##
==========================================
- Coverage   91.74%   91.73%   -0.01%     
==========================================
  Files         174      174              
  Lines       50748    50748              
==========================================
- Hits        46557    46556       -1     
- Misses       4191     4192       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.25% <100%> (+0.01%)` | :arrow_up: |
| #single | `41.69% <0%> (-0.09%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26426?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/26426/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `97.52% <100%> (+0.82%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26426/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26426/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.02% <0%> (-0.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26426?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/26426?src=pr&el=footer). Last update [f44ac06...c7d58af](https://codecov.io/gh/pandas-dev/pandas/pull/26426?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jreback 

running _test_fast.bat_ produces many failed tests. However I can't find _test_multi_line_expression_callable_local_variable_ in the output. Does this mean that this test is passed?
@jreback 
can you have a look at the new commit? Thank you
you will need to merge master as well, there is a conflict
Th conflict is now resolved
thanks for the patch @danielhrisca