validate min/max axis
State: closed

Broken off from #23140.

- [x] closes #23081 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Refactor
description: Internal refactoring of code

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

 - There are no PEP8 issues in the file [`pandas/compat/numpy/function.py`](https://github.com/jbrockmendel/pandas/blob/0e8ac5fbf4f839744893af1e17112c967fc0b34c/pandas/compat/numpy/function.py) !

 - There are no PEP8 issues in the file [`pandas/core/indexes/datetimelike.py`](https://github.com/jbrockmendel/pandas/blob/0e8ac5fbf4f839744893af1e17112c967fc0b34c/pandas/core/indexes/datetimelike.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/datetimelike.py`](https://github.com/jbrockmendel/pandas/blob/0e8ac5fbf4f839744893af1e17112c967fc0b34c/pandas/tests/indexes/datetimelike.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23206?src=pr&el=h1) Report
> Merging [#23206](https://codecov.io/gh/pandas-dev/pandas/pull/23206?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9285820d33d4986769a84f3db5f25cff8bf85d8d?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #23206      +/-   ##
==========================================
+ Coverage   92.19%   92.19%   +<.01%     
==========================================
  Files         169      169              
  Lines       50954    50964      +10     
==========================================
+ Hits        46975    46985      +10     
  Misses       3979     3979
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <100%> (ø)` | :arrow_up: |
| #single | `42.26% <10%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23206?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/compat/numpy/function.py](https://codecov.io/gh/pandas-dev/pandas/pull/23206/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9udW1weS9mdW5jdGlvbi5weQ==) | `87.13% <100%> (+0.46%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/23206/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `98.25% <100%> (+0.02%)` | :arrow_up: |

------

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

this is not correct - why did you merge??
this is very verbose code and needs to be incorporated to the validation rather than done in the DatetimeArray
Seems good to me. Shall we revert?
The argument made on the previous PR is that those two validations are not really the same, so they don't necessarily need to live in the same function
i disagree

we have a well thought out pattern for handling these validations

this should be integral to the current framework rather than simply adding another function call
I think the question is whether you see this as a "numpy compatibility" check, or rather a general keyword arg validation check (as we do in many places in pandas). In the first case you are right this should be integrated, in the second case I think separate is fine, and the function should actually be moved to `_validators.py`. 
I think for that question we could go either way, but I personally lean more toward this being a general check.
this should be part of the existing check

the issue as written is that you have to remember to add this in addition. to _validate_min for example
whereas it should just be part of that

this is just cause for bugs laters on as written
@jreback the new axis validation func assumes self.ndim==1, which nothing else in compat.numpy.functions does.  Adding that assumption into a subset of that module's functions is much smellier than making an explicit function call in four place.s

If we were to combine the axis check into the existing functions, two possible approaches come to mind.  The first is to wrap the extant functions and [pin](https://github.com/pandas-dev/pandas/pull/23140/files#diff-65c367c0378964470736d576684d49e4R69) the new one to them.  You disapproved of this when implemented in #23140.

The second approach is to modify the function-generating code and bake in this new check to everything in compat.functions.numpy.  Besides not being clear that we want this check in all the other affected functions, these way these functions are generated is opaque to newcomers (yo!) and changing the generating code will end up much more verbose than the 4 lines of function calls in this implementation.