CLN: ASV frame_methods benchmark
State: closed

- Added `np.random.seed(1234)` in setup classes where random data is created xref #8144

- Ran flake8 and replaced star imports

- Moved `GetItemSingleColumn`, `AssignTimeseriesIndex`, and `InsertColumns` to `indexing.py`, and `StringSlice` to `strings.py`

- Refactored to use `params` where relevant

```
$asv dev -b ^frame_methods

[  1.79%] ··· Running frame_methods.Apply.time_apply_axis_1                                                        299ms
[  3.57%] ··· Running frame_methods.Apply.time_apply_lambda_mean                                                  12.0ms
[  5.36%] ··· Running frame_methods.Apply.time_apply_np_mean                                                      13.4ms
[  7.14%] ··· Running frame_methods.Apply.time_apply_pass_thru                                                    13.5ms
[  8.93%] ··· Running frame_methods.Apply.time_apply_ref_by_name                                                  69.1ms
[ 10.71%] ··· Running frame_methods.Apply.time_apply_user_func                                                     256ms
[ 12.50%] ··· Running frame_methods.Count.time_count_level_mixed_dtypes_multi                                         ok
[ 12.50%] ···· 
               ====== =======
                axis         
               ------ -------
                 0     157ms 
                 1     128ms 
               ====== =======

[ 14.29%] ··· Running frame_methods.Count.time_count_level_multi                                                      ok
[ 14.29%] ···· 
               ====== =======
                axis         
               ------ -------
                 0     113ms 
                 1     147ms 
               ====== =======

[ 16.07%] ··· Running frame_methods.Dropna.time_dropna                                                                ok
[ 16.07%] ···· 
               ===== ======== ========
               --           axis      
               ----- -----------------
                how     0        1    
               ===== ======== ========
                all   135ms    150ms  
                any   60.8ms   63.0ms 
               ===== ======== ========

[ 17.86%] ··· Running frame_methods.Dropna.time_dropna_axis_mixed_dtypes                                              ok
[ 17.86%] ···· 
               ===== ======= =======
               --          axis     
               ----- ---------------
                how     0       1   
               ===== ======= =======
                all   437ms   436ms 
                any   346ms   327ms 
               ===== ======= =======

[ 19.64%] ··· Running frame_methods.Dtypes.time_frame_dtypes                                                       336μs
[ 21.43%] ··· Running frame_methods.Duplicated.time_frame_duplicated                                               340ms
[ 23.21%] ··· Running frame_methods.Duplicated.time_frame_duplicated_wide                                          353ms
[ 25.00%] ··· Running frame_methods.Equals.time_frame_float_equal                                                 8.72ms
[ 26.79%] ··· Running frame_methods.Equals.time_frame_float_unequal                                               24.4ms
[ 28.57%] ··· Running frame_methods.Equals.time_frame_nonunique_equal                                             11.8ms
[ 30.36%] ··· Running frame_methods.Equals.time_frame_nonunique_unequal                                           12.1ms
[ 32.14%] ··· Running frame_methods.Equals.time_frame_object_equal                                                41.4ms
[ 33.93%] ··· Running frame_methods.Equals.time_frame_object_unequal                                              27.3ms
[ 35.71%] ··· Running frame_methods.Fillna.time_frame_fillna                                                          ok
[ 35.71%] ···· 
               ========= ======== ========
               --              method     
               --------- -----------------
                inplace    pad     bfill  
               ========= ======== ========
                  True    14.7ms   18.8ms 
                 False    12.7ms   13.3ms 
               ========= ======== ========

[ 37.50%] ··· Running frame_methods.FromRecords.time_frame_from_records_generator                                     ok
[ 37.50%] ···· 
               ======= ========
                nrows          
               ------- --------
                 None   136ms  
                 1000   2.23ms 
               ======= ========

[ 39.29%] ··· Running frame_methods.GetDtypeCounts.time_frame_get_dtype_counts                                     493μs
[ 41.07%] ··· Running frame_methods.GetDtypeCounts.time_info                                                       999ms
[ 41.07%] ····· <class 'pandas.core.frame.DataFrame'>
                RangeIndex: 10 entries, 0 to 9
                Columns: 10000 entries, 0 to 9999
                dtypes: float64(10000)
                memory usage: 781.3 KB

[ 42.86%] ··· Running frame_methods.GetNumericData.time_frame_get_numeric_data                                     411μs
[ 42.86%] ····· /home/matt/Projects/pandas-mroeschke/asv_bench/benchmarks/frame_methods.py:17: FutureWarning: consolidate is deprecated and will be removed in a future release.
                self.df = self.df.consolidate()

[ 44.64%] ··· Running frame_methods.Interpolate.time_interpolate                                                      ok
[ 44.64%] ···· 
               ========== ========
                downcast          
               ---------- --------
                  None     98.8ms 
                 infer     159ms  
               ========== ========

[ 46.43%] ··· Running frame_methods.Interpolate.time_interpolate_some_good                                            ok
[ 46.43%] ···· 
               ========== ========
                downcast          
               ---------- --------
                  None     3.02ms 
                 infer     6.04ms 
               ========== ========

[ 48.21%] ··· Running frame_methods.Isnull.time_isnull                                                            2.42ms
[ 50.00%] ··· Running frame_methods.Isnull.time_isnull_floats_no_null                                             2.45ms
[ 51.79%] ··· Running frame_methods.Isnull.time_isnull_obj                                                        89.7ms
[ 53.57%] ··· Running frame_methods.Isnull.time_isnull_strngs                                                     79.3ms
[ 55.36%] ··· Running frame_methods.Iteration.time_iteritems                                                      87.8ms
[ 57.14%] ··· Running frame_methods.Iteration.time_iteritems_cached                                               87.6ms
[ 58.93%] ··· Running frame_methods.Iteration.time_iteritems_indexing                                              450ms
[ 60.71%] ··· Running frame_methods.Iteration.time_itertuples                                                     81.1ms
[ 62.50%] ··· Running frame_methods.Lookup.time_frame_fancy_lookup                                                8.36ms
[ 64.29%] ··· Running frame_methods.Lookup.time_frame_fancy_lookup_all                                            55.2ms
[ 66.07%] ··· Running frame_methods.MaskBool.time_frame_mask_bools                                                26.0ms
[ 67.86%] ··· Running frame_methods.MaskBool.time_frame_mask_floats                                               19.2ms
[ 69.64%] ··· Running frame_methods.Nlargest.time_frame_nlargest                                                  3.73ms
[ 71.43%] ··· Running frame_methods.Nunique.time_frame_nunique                                                     679ms
[ 73.21%] ··· Running frame_methods.Quantile.time_frame_quantile                                                      ok
[ 73.21%] ···· 
               ====== ========
                axis          
               ------ --------
                 0     995μs  
                 1     1.59ms 
               ====== ========

[ 75.00%] ··· Running frame_methods.Reindex.time_reindex_axis0                                                    17.7ms
[ 76.79%] ··· Running frame_methods.Reindex.time_reindex_axis1                                                     140ms
[ 78.57%] ··· Running frame_methods.Reindex.time_reindex_both_axes                                                53.3ms
[ 80.36%] ··· Running frame_methods.Reindex.time_reindex_both_axes_ix                                             53.9ms
[ 82.14%] ··· Running frame_methods.Reindex.time_reindex_upcast                                                   15.4ms
[ 83.93%] ··· Running frame_methods.Repr.time_frame_repr_wide                                                     32.0ms
[ 85.71%] ··· Running frame_methods.Repr.time_html_repr_trunc_mi                                                   429ms
[ 87.50%] ··· Running frame_methods.Repr.time_html_repr_trunc_si                                                   405ms
[ 89.29%] ··· Running frame_methods.Repr.time_repr_tall                                                           52.2ms
[ 91.07%] ··· Running frame_methods.Shift.time_shift                                                                  ok
[ 91.07%] ···· 
               ====== ========
                axis          
               ------ --------
                 0     41.7ms 
                 1     45.1ms 
               ====== ========

[ 92.86%] ··· Running frame_methods.SortIndex.time_frame_sort_index                                                   ok
[ 92.86%] ···· 
               =========== ========
                ascending          
               ----------- --------
                   True     21.1ms 
                  False     139ms  
               =========== ========

[ 94.64%] ··· Running frame_methods.SortIndexByColumns.time_frame_sort_index_by_columns                           66.1ms
[ 94.64%] ····· /home/matt/Projects/pandas-mroeschke/asv_bench/benchmarks/frame_methods.py:498: FutureWarning: by argument to sort_index is deprecated, pls use .sort_values(by=...)
                self.df.sort_index(by=['key1', 'key2'])

[ 96.43%] ··· Running frame_methods.ToHTML.time_to_html_mixed                                                      527ms
[ 98.21%] ··· Running frame_methods.ToString.time_to_string_floats                                                72.4ms
[100.00%] ··· Running frame_methods.XS.time_frame_xs                                                                  ok
[100.00%] ···· 
               ====== =======
                axis         
               ------ -------
                 0     791μs 
                 1     674μs 
               ====== =======
```

Labels:
name: Benchmark
description: Performance (ASV) benchmarks

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=h1) Report
> Merging [#18536](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/88ab6934e78117359719eb09c7d580906155575d?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #18536      +/-   ##
==========================================
- Coverage   91.35%   91.33%   -0.02%     
==========================================
  Files         164      164              
  Lines       49801    49801              
==========================================
- Hits        45494    45485       -9     
- Misses       4307     4316       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.13% <ø> (ø)` | :arrow_up: |
| #single | `40.81% <ø> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18536?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/18536?src=pr&el=footer). Last update [88ab693...b0956ae](https://codecov.io/gh/pandas-dev/pandas/pull/18536?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/18536?src=pr&el=h1) Report
> Merging [#18536](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/32f562dbe459ee9e437da3a67631949d34531411?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #18536      +/-   ##
==========================================
- Coverage   91.35%   91.33%   -0.02%     
==========================================
  Files         164      164              
  Lines       49802    49802              
==========================================
- Hits        45496    45487       -9     
- Misses       4306     4315       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.13% <ø> (ø)` | :arrow_up: |
| #single | `40.81% <ø> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18536?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <0%> (-0.1%)` | :arrow_down: |

------

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

@jorisvandenbossche Nice catch; you were correct about the setup. I was able to define a `setup` function in `.pandas_vb_common.py` and import it to set the random seed (confirmed with a small test with `asv dev` and a `print` statement). However, we have to live with the lint error, `F811 redefinition of unused 'setup' from line x`.

Otherwise, moved `FromRecords` to `frame_ctor.py`, added an `iterrows` benchmark, changed `sort_index` to `sort_values`, and kept the `NSort` class which now benches `nsmallest` and `nlargest` with params.
Apart from the small comment, looks good to me!
Since this is not linted anyhow, not that urgent (although nice for local use that it doesn't give a lint error). So you can always fix it if you do another PR on this.

Thanks!