STYLE: #22885, Moved all setup imports to bottom of benchmark files and added noqa: F401 to each
State: closed

- [x] closes #22885 
- [ ] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

#22885 

Following the suggestions of @datapythonista, I moved all the `setup` imports for the benchmark files to the end of each file and added a `# noqa: F401` like so:

`from .pandas_vb_common import setup  # noqa: F401`

Now, `flake8` only returns the following two errors in `asv_bench`:

```
./benchmarks/strings.py:95:9: E731 do not assign a lambda expression, use a def
./benchmarks/io/excel.py:6:1: F401 '..pandas_vb_common.BaseIO' imported but unused
```

These may be expected, but I wanted to mention them here just in case they need addressing.

Also, running `pytest`, I got this error:

```
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --strict-data-files
  inifile: /pandas/setup.cfg
  rootdir: /pandas
```

I found a discussion on it at #22700, but there didn't seem to be a definitive solution. Open to guidance on this.

Please let me know if any corrections are needed. Thanks!

Labels:
name: Code Style
description: Code style, linting, code_checks
name: Benchmark
description: Performance (ASV) benchmarks

Comments:
Hello @jerodestapa! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/algorithms.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/algorithms.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/attrs_caching.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/attrs_caching.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/binary_ops.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/binary_ops.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/categoricals.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/categoricals.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/ctors.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/ctors.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/eval.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/eval.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/frame_ctor.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/frame_ctor.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/frame_methods.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/frame_methods.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/gil.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/gil.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/groupby.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/groupby.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/index_object.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/index_object.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/indexing.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/indexing.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/inference.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/inference.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/csv.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/csv.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/excel.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/excel.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/hdf.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/hdf.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/json.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/json.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/msgpack.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/msgpack.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/pickle.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/pickle.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/sql.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/sql.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/io/stata.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/io/stata.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/join_merge.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/join_merge.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/multiindex_object.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/multiindex_object.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/panel_ctor.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/panel_ctor.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/panel_methods.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/panel_methods.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/plotting.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/plotting.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/reindex.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/reindex.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/replace.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/replace.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/reshape.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/reshape.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/rolling.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/rolling.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/series_methods.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/series_methods.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/sparse.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/sparse.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/stat_ops.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/stat_ops.py) !

 - There are no PEP8 issues in the file [`asv_bench/benchmarks/timeseries.py`](https://github.com/jerodestapa/pandas/blob/9b8441bd095b05075e37b4d578bf4e0589305d9f/asv_bench/benchmarks/timeseries.py) !


Thanks for the work on this @jerodestapa 
For the pytest issue, `pytest pandas` should work.

I think we're doing something wrong with how we register new command line options, but I'm not familiar enough with pytest plugins to know how to fix it.
You bet, @datapythonista. Thanks for suggestions. I agree it's less than ideal, but as you say, it's the best solution given the constraints around flake8.

@TomAugspurger, it's not liking something about `setup.cfg` and the default option `addopts = --strict-data-files --durations=10`, but it may just be a local issue on my end. I'll let you know if I figure it out, though.
can you rebase
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22947?src=pr&el=h1) Report
> Merging [#22947](https://codecov.io/gh/pandas-dev/pandas/pull/22947?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ca7d518cba8e1c6ed96328fed8968afb23588077?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #22947      +/-   ##
==========================================
- Coverage   92.19%   92.19%   -0.01%     
==========================================
  Files         169      169              
  Lines       50904    50911       +7     
==========================================
+ Hits        46933    46939       +6     
- Misses       3971     3972       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <ø> (-0.01%)` | :arrow_down: |
| #single | `42.3% <ø> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22947?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/22947/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2NvbmNhdC5weQ==) | `98% <0%> (-0.38%)` | :arrow_down: |
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/22947/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `95.58% <0%> (+0.03%)` | :arrow_up: |

------

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

My apologies on the wait, @jreback. Let me know if anything else needs fixing.

Thanks.
Not sure if you've seen it @jerodestapa, but seems like you've got unrelated changes in this PR.

If you don't find a better way to fix it, usually the next steps could fix it (in the PR branch):
- `git fetch upstream`
- `git merge upstream/master`
- `git reset --soft upstream/master`
- `git commit -m "your pr comment"`
- `git push -f`

This will delete the history of your changes, but should leave your changes and nothing else.
Thanks, @datapythonista. I must have done something weird when rebasing. I just reset and pushed again.
this looks fine. can you run the asv's just to be sure things still work.
@jreback: The asv's are still running, but it looks like the four files that updated when I rebased (`indexing.py`, `join_merge.py`, `panel_ctor.py`, and `panel_methods.py`) still have the `from .pandas_vb_common import Panel` line instead of importing `Panel` from `pandas`. Should I remove those lines and make another commit, or rebase again?
I think the PR is ok as it is. Not sure why `Panel` was being imported from `pandas_vb_common.py` instead of directly, but as your changes already fix the linting, and `Panel` will be removed soon anyway, I think it's worth just leaving it as it was.

I think this is ready to be merged, thanks for the work @jerodestapa 
Awesome. Thanks for all the help, guys. This was my first PR for pandas, and it's just exciting to contribute. Thanks, again.
Hopefully not the last one @jerodestapa ;)