CLN: replace %s syntax with .format in core.computation
State: closed

Progress towards #16130

- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Replaced `%s` syntax with `.format` in core.computation.  Additionally, made some of the existing positional `.format` code more explicit by modifying things like `'{0}'.format(foo)` to `'{foo}'.format(foo=foo)`.

Doesn't seem like adding tests or a whatsnew entry is relevant, and I'm not sure what a test here would look like, but I'd be happy to add either if relevant.

Labels:
name: Clean

Comments:
I found a weird case, and I'd like to confirm that what I'm doing is correct:

In the original `%` formatting version of the code, there's the following line in [pytables.py#532](https://github.com/pandas-dev/pandas/blob/master/pandas/core/computation/pytables.py#L532):
```python
where = ' & ' .join(["(%s)" % w for w in where])  # noqa
```

I originally switched this to `.format` via:
```python
where = ' & '.join(map('({})'.format, where))  # noqa
```
However, this didn't work and ended up failing a test in [test_pytables.py](https://github.com/pandas-dev/pandas/blob/master/pandas/tests/io/test_pytables.py#L2584-L2667).  Specifically, it failed because the test is passing nested tuples, such as `((("minor_axis==['A', 'B']"),),)`.  It looks like the `%` formatting code was using the fact that `%` formatting takes the first nested element of such a tuple, whereas `.format` formats the tuple as a whole.  My workaround was to use the `pandas.core.common.flatten` function as such:
```python
where = ' & '.join(map('({})'.format, com.flatten(where)))  # noqa
```

This passes the test that previously failed, but I'm not positive that it's the correct thing to do in all cases.  Can someone confirm that this is right, or suggest an appropriate alternative?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=h1) Report
> Merging [#17209](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/073c14544436d95969258928e2554cb2fc093c99?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `69.23%`.

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

```diff
@@            Coverage Diff             @@
##           master   #17209      +/-   ##
==========================================
- Coverage   91.03%   91.01%   -0.02%     
==========================================
  Files         162      162              
  Lines       49511    49515       +4     
==========================================
- Hits        45070    45064       -6     
- Misses       4441     4451      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.79% <46.15%> (-0.01%)` | :arrow_down: |
| #single | `40.26% <46.15%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/computation/expressions.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwcmVzc2lvbnMucHk=) | `0% <ø> (ø)` | :arrow_up: |
| [pandas/core/computation/eval.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXZhbC5weQ==) | `96.96% <100%> (+0.03%)` | :arrow_up: |
| [pandas/core/computation/align.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vYWxpZ24ucHk=) | `97.93% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/computation/engines.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZW5naW5lcy5weQ==) | `88.88% <100%> (ø)` | :arrow_up: |
| [pandas/core/computation/scope.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vc2NvcGUucHk=) | `93.13% <33.33%> (-0.93%)` | :arrow_down: |
| [pandas/core/computation/expr.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwci5weQ==) | `88.48% <63.63%> (ø)` | :arrow_up: |
| [pandas/core/computation/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vcHl0YWJsZXMucHk=) | `92.37% <66.66%> (+0.02%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17209?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.71% <0%> (-0.1%)` | :arrow_down: |

------

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

https://github.com/pandas-dev/pandas/pull/17209#issuecomment-321448013 is not very useful anymore. so that is fine.
thanks