Repository: modin-project/modin

Issue:
TypeError: __array__() takes 1 positional argument but 2 were given
### System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Windows 10
- **Modin version** (`modin.__version__`): 0.10.0
- **Python version**: 3.8.10 64-bit
- **Code we can use to reproduce**:

To run the test, clone the repository, install the dependencies, activate the installed virtual environment, and run the command:

```shell
  set MODIN_EXPERIMENTAL=1
  set MODIN_ENGINE=Python
  python -m pytest --simulate-cloud=normal modin/pandas/test/dataframe/test_binary.py::test_math_functions[add-rows-scalar]
```

### Describe the problem

<details>
  <summary>There are two very similar problems that can be solved as follows</summary>

  1. Opening file `rpyc\core\netref.py` ([link](https://github.com/tomerfiliba-org/rpyc/blob/master/rpyc/core/netref.py) on GitHub)
  2. Looking in the file `def __array__` ([link](https://github.com/tomerfiliba-org/rpyc/blob/9aa4d64f49cd85941e4c378c55b8abb1496d06e7/rpyc/core/netref.py#L252) on GitHub)
  3. Replacing this:

      ```py
        def __array__(self):
            # Note that protocol=-1 will only work between python
            # interpreters of the same version.
            return pickle.loads(syncreq(self, consts.HANDLE_PICKLE, -1))
      ```

      For this:

      ```py
        def __array__(self, dtype=None):
            # Note that protocol=-1 will only work between python
            # interpreters of the same version.
            res = pickle.loads(syncreq(self, consts.HANDLE_PICKLE, -1))

            if dtype is not None:
                import numpy
                res = numpy.asarray(res, dtype=dtype)

            return res
      ```

</details>

The first of these problems occurs in 2305 tests:

- modin/pandas/test/dataframe/test_binary.py::test_math_functions[add-rows-scalar]
- modin/pandas/test/dataframe/test_binary.py::test_math_functions[add-rows-series_or_list]
- modin/pandas/test/dataframe/test_binary.py::test_math_functions[add-columns-scalar]

And also in 2302 tests.

The second of these problems occurs in 1637 tests:

- modin/pandas/test/dataframe/test_join_sort.py::test_sort_values[None-ignore_index_True-first-quicksort-inplace_True-ascending_True-over_rows_int-multiindex_level0-int_data]
- modin/pandas/test/dataframe/test_join_sort.py::test_sort_values[None-ignore_index_True-first-quicksort-inplace_True-ascending_True-over_rows_int-multiindex_level1,multiindex_level0-int_data]
- modin/pandas/test/dataframe/test_join_sort.py::test_sort_values[None-ignore_index_True-first-quicksort-inplace_True-ascending_True-over_rows_int-multiindex_level0,last,first,multiindex_level1-int_data]

And also in 1634 tests.

Perhaps fixing this bug will also solve the problems in the following tests, since the problem is most likely the same:

- modin/pandas/test/dataframe/test_indexing.py::test_reset_index_with_multi_index_no_drop[True-0-False-no_col_fill-no_col_level-no_level-True-3-float_nan_data]
- modin/pandas/test/dataframe/test_indexing.py::test_reset_index_with_multi_index_no_drop[True-0-False-no_col_fill-no_col_level-None-True-3-float_nan_data]
- modin/pandas/test/dataframe/test_indexing.py::test_reset_index_with_multi_index_no_drop[True-0-False-no_col_fill-no_col_level-0-True-3-float_nan_data]

And also in 2433 tests.

### Source code / logs

<details>
    <summary>Part's traceback for first problem:</summary>

    ======= Remote Traceback =======
    E     File  "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\internals \construction.py", line 355, in _homogenize
    E       val = sanitize_array(
    E     File  "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\construct ion.py", line 482, in sanitize_array
    E       subarr = maybe_convert_platform(data)
    E     File  "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\dtypes\ca st.py", line 112, in maybe_convert_platform
    E       values = construct_1d_object_array_from_listlike(values)
    E     File  "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\dtypes\ca st.py", line 1639, in construct_1d_object_array_from_listlike
    E       result[:] = values
    E   TypeError: __array__() takes 1 positional argument but 2 were given

</details>

<details>
    <summary>Part's traceback for second problem:</summary>

    ======= Remote Traceback =======
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\series.py", line 364, in __init__
    E       data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\construction.py", line 480, in sanitize_array
    E       subarr = _try_cast(data, dtype, copy, raise_cast_failure)
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\construction.py", line 598, in _try_cast
    E       subarr = construct_1d_object_array_from_listlike(subarr)
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\dtypes\cast.py", line 1639, in construct_1d_object_array_from_listlike
    E       result[:] = values
    E   TypeError: __array__() takes 1 positional argument but 2 were given

</details>

<details>
    <summary>Part's traceback for third problem:</summary>

    ======= Remote Traceback =======
    E       self._get_axis(axis).identical(ax)
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\indexes\base.py", line 4485, in identical
    E       self.equals(other)
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\indexes\multi.py", line 3464, in equals
    E       other_values = algos.take_nd(
    E     File "C:\Users\alozovsk\Anaconda3\envs\modin\lib\site-packages\pandas\core\algorithms.py", line 1708, in take_nd
    E       indexer = ensure_int64(indexer, copy=False)
    E     File "pandas\_libs\algos_common_helper.pxi", line 93, in pandas._libs.algos.ensure_int64
    E   TypeError: __array__() takes 1 positional argument but 2 were given 

</details>



Discussion:

Resolving patch:
diff --git a/modin/experimental/cloud/rpyc_patches.py b/modin/experimental/cloud/rpyc_patches.py
new file mode 100644
--- /dev/null
+++ b/modin/experimental/cloud/rpyc_patches.py
@@ -0,0 +1,42 @@
+# 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
+from rpyc.core import netref
+
+
+def apply_pathes():
+    def fixed_make_method(name, doc, orig=netref._make_method):
+        if name == "__array__":
+
+            def __array__(self, dtype=None):
+                # Note that protocol=-1 will only work between python
+                # interpreters of the same version.
+                res = netref.pickle.loads(
+                    netref.syncreq(
+                        self,
+                        netref.consts.HANDLE_PICKLE,
+                        netref.pickle.HIGHEST_PROTOCOL,
+                    )
+                )
+
+                if dtype is not None:
+                    res = numpy.asarray(res, dtype=dtype)
+
+                return res
+
+            __array__.__doc__ = doc
+            return __array__
+        return orig(name, doc)
+
+    netref._make_method = fixed_make_method
diff --git a/modin/experimental/cloud/rpyc_proxy.py b/modin/experimental/cloud/rpyc_proxy.py
--- a/modin/experimental/cloud/rpyc_proxy.py
+++ b/modin/experimental/cloud/rpyc_proxy.py
@@ -24,6 +24,11 @@
 from .meta_magic import _LOCAL_ATTRS, RemoteMeta, _KNOWN_DUALS
 from modin.config import DoTraceRpyc
 
+from .rpyc_patches import apply_pathes
+
+
+apply_pathes()
+
 
 def _batch_loads(items):
     return tuple(pickle.loads(item) for item in items)
@@ -209,11 +214,7 @@ def __getattribute__(this, name):
                         return res
                 return orig_getattribute(this, name)
 
-            def __array__(this):
-                return pickle.loads(self._remote_pickled_array(this))
-
             cls.__getattribute__ = __getattribute__
-            cls.__array__ = __array__
         return result
 
     def _netref_factory(self, id_pack):


Test patch: