Repository: modin-project/modin

Issue:
BUG: np.argmax/argmin on 1D arrays are broken
### Modin version checks

- [X] I have checked that this issue has not already been reported.

- [X] I have confirmed this bug exists on the latest released version of Modin.

- [X] I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow [this guide](https://modin.readthedocs.io/en/stable/getting_started/installation.html#installing-from-the-github-master-branch).)


### Reproducible Example

```python
np.argmax(np.array([-87.434,-90.908, -87.152, -84.903]))
# Returns 0 (should return 3)
```


### Issue Description

A few internal logic bugs in argmax/argmin are producing the incorrect result.

### Expected Behavior

Return the same value as numpy does.

### Error Logs

<details>

```python-traceback

Replace this line with the error backtrace (if applicable).

```

</details>


### Installed Versions

<details>
INSTALLED VERSIONS
------------------
commit           : d5f3f723bbe0f941b28e8a09ef1fac3e4579f7a9
python           : 3.10.4.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 22.2.0
Version          : Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

Modin dependencies
------------------
modin            : 0.19.0+11.gd5f3f723.dirty
ray              : 1.13.0
dask             : 2022.8.0
distributed      : 2022.8.0
hdk              : None

pandas dependencies
-------------------
pandas           : 1.5.3
numpy            : 1.23.1
pytz             : 2022.1
dateutil         : 2.8.2
setuptools       : 61.2.0
pip              : 22.1.2
Cython           : None
pytest           : 7.1.2
hypothesis       : None
sphinx           : 5.1.1
blosc            : None
feather          : 0.4.1
xlsxwriter       : None
lxml.etree       : 4.9.1
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.1.2
IPython          : 8.4.0
pandas_datareader: None
bs4              : 4.11.1
bottleneck       : None
brotli           : None
fastparquet      : 0.8.2
fsspec           : 2022.7.1
gcsfs            : None
matplotlib       : 3.5.3
numba            : None
numexpr          : 2.8.3
odfpy            : None
openpyxl         : 3.0.10
pandas_gbq       : 0.17.8
pyarrow          : 8.0.0
pyreadstat       : None
pyxlsb           : None
s3fs             : 2022.7.1
scipy            : 1.9.0
snappy           : None
sqlalchemy       : 1.4.40
tables           : 3.7.0
tabulate         : None
xarray           : 2022.6.0
xlrd             : 2.0.1
xlwt             : None
zstandard        : None
tzdata           : None

</details>



Discussion:

Resolving patch:
diff --git a/modin/numpy/arr.py b/modin/numpy/arr.py
--- a/modin/numpy/arr.py
+++ b/modin/numpy/arr.py
@@ -2179,9 +2179,9 @@ def argmax(self, axis=None, out=None, keepdims=None):
                 raise numpy.AxisError(1, 1)
             if self._query_compiler.isna().any(axis=1).any(axis=0).to_numpy()[0, 0]:
                 na_row_map = self._query_compiler.isna().any(axis=1)
-                result = na_row_map.idxmax().to_numpy()[0, 0]
+                result = na_row_map.idxmax()
             else:
-                result = self._query_compiler.idxmax(axis=1)
+                result = self._query_compiler.idxmax(axis=0)
             if keepdims:
                 if out is not None and out.shape != (1,):
                     raise ValueError(
@@ -2248,7 +2248,9 @@ def argmin(self, axis=None, out=None, keepdims=None):
                 raise numpy.AxisError(1, 1)
             if self._query_compiler.isna().any(axis=1).any(axis=0).to_numpy()[0, 0]:
                 na_row_map = self._query_compiler.isna().any(axis=1)
-                result = na_row_map.idxmax().to_numpy()[0, 0]
+                # numpy apparently considers nan to be the minimum value in an array if present
+                # therefore, we use idxmax on the mask array to identify where nans are
+                result = na_row_map.idxmax()
             else:
                 result = self._query_compiler.idxmin(axis=0)
             if keepdims:


Test patch:
diff --git a/modin/numpy/test/test_array_math.py b/modin/numpy/test/test_array_math.py
new file mode 100644
--- /dev/null
+++ b/modin/numpy/test/test_array_math.py
@@ -0,0 +1,33 @@
+# Licensed to Modin Development Team under one or more contributor license agreements.
+# See the NOTICE file distributed with this work for additional information regarding
+# copyright ownership.  The Modin Development Team licenses this file to you under the
+# Apache License, Version 2.0 (the "License"); you may not use this file except in
+# compliance with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under
+# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+# ANY KIND, either express or implied. See the License for the specific language
+# governing permissions and limitations under the License.
+
+import numpy
+import pytest
+
+import modin.numpy as np
+
+
+@pytest.mark.parametrize(
+    "data",
+    [
+        [3, 2, 1, 1],
+        [-87.434, -90.908, -87.152, -84.903],
+        [-87.434, -90.908, np.nan, -87.152, -84.903],
+    ],
+    ids=["ints", "floats", "floats with nan"],
+)
+@pytest.mark.parametrize("op", ["argmin", "argmax"])
+def test_argmax_argmin(data, op):
+    numpy_result = getattr(numpy, op)(numpy.array(data))
+    modin_result = getattr(np, op)(np.array(data))
+    numpy.testing.assert_array_equal(modin_result, numpy_result)