BUG: incorrect argument order to _copyto in in np.nanmax, np.nanmin

In https://github.com/astropy/astropy/issues/2340, it was noticed that `np.nanmax` on the `ndarray` subclass `Quantity` did not work properly. This can be traced to the arguments to the `_copyto` call in `numpy.lib/nanfunctions` not being in the correct order:
```
res = _copyto(res, mask, np.nan)
```
while the call sequence to `_copyto` is
```
def _copyto(a, val, mask):
```

This PR corrects the two occurrences of this mistake. 

Obviously, it should also add test cases, and the simplest would seem to be to run all the ones in `test_nanfunctions.py` with an `ndarray` subclass. Is there an easy way to implement this?