BUG: fix numpy min/max compat with index (#26125)
State: closed

- [x] closes #26125
- [x] 2 tests added
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


When working on the original issue, I came across something similar :
- `RangeIndex` had its own implementation of `max`/`min` with the same behavior
- `Index` & `RangeIndex` could both benefit from adding another compat call

```
In [5]: np.argmin(pd.Index([1,2,3]), out=0)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
venv\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     55     try:
---> 56         return getattr(obj, method)(*args, **kwds)
     57

TypeError: argmin() got an unexpected keyword argument 'out'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-5-5c9b894867ef> in <module>
----> 1 np.argmin(pd.Index([1,2,3]), out=0)

venv\lib\site-packages\numpy\core\fromnumeric.py in argmin(a, axis, out)
   1170
   1171     """
-> 1172     return _wrapfunc(a, 'argmin', axis=axis, out=out)
   1173
   1174

venv\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     64     # a downstream library like 'pandas'.
     65     except (AttributeError, TypeError):
---> 66         return _wrapit(obj, method, *args, **kwds)
     67
     68

venv\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     44     except AttributeError:
     45         wrap = None
---> 46     result = getattr(asarray(obj), method)(*args, **kwds)
     47     if wrap:
     48         if not isinstance(result, mu.ndarray):

TypeError: output must be an array
```
I changed it to be consistent with the rest of pandas `ValueError: the 'out' parameter is not supported in the pandas implementation of argmax()`.



Labels:
name: Compat
description: pandas objects compatability with Numpy or Python functions

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

```diff
@@            Coverage Diff             @@
##           master   #26324      +/-   ##
==========================================
- Coverage   92.04%   92.03%   -0.01%     
==========================================
  Files         175      175              
  Lines       52291    52297       +6     
==========================================
+ Hits        48132    48134       +2     
- Misses       4159     4163       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.59% <100%> (ø)` | :arrow_up: |
| #single | `40.74% <50%> (-0.16%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26324?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/range.py](https://codecov.io/gh/pandas-dev/pandas/pull/26324/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9yYW5nZS5weQ==) | `97.97% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26324/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `98% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26324/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/26324/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.01% <0%> (-0.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26324?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/26324?src=pr&el=footer). Last update [d024aae...4f1eecd](https://codecov.io/gh/pandas-dev/pandas/pull/26324?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/26324?src=pr&el=h1) Report
> Merging [#26324](https://codecov.io/gh/pandas-dev/pandas/pull/26324?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/d024aaef04f938f30ef926e7839ac70e5311f1d1?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/26324/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26324?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26324      +/-   ##
==========================================
- Coverage   92.04%   92.03%   -0.01%     
==========================================
  Files         175      175              
  Lines       52291    52297       +6     
==========================================
+ Hits        48132    48134       +2     
- Misses       4159     4163       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.59% <100%> (ø)` | :arrow_up: |
| #single | `40.74% <50%> (-0.16%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26324?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/range.py](https://codecov.io/gh/pandas-dev/pandas/pull/26324/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9yYW5nZS5weQ==) | `97.97% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26324/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `98% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26324/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/26324/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.01% <0%> (-0.12%)` | :arrow_down: |

------

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

thanks @Batalex 
I'm a bit surprised at the performance impact here http://pandas.pydata.org/speed/pandas/#index_object.Range.time_min (about 20-25%). It may be worth seeing if the performance of our numpy compat validators can be improved.
On second thought, maybe the relative perf slowdown isn't too surprising, since RangeIndex.min / max is basically free. So it looks like a large slowdown, but in absolute terms it's not so bad... Still may be worth profiling things to see if there's any easy wins to be had in the validators (as in theory those should be cheap too).