Repository: modin-project/modin

Issue:
BUG: merge_asof with non-unique index on right frame raises ValueError
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: macOS Monterey 12.2.1
- **Modin version** (`modin.__version__`): b22b93df20ad25ae7a11f0c89d32fb2f234d4641
- **Python version**: 3.9.12
- **Code we can use to reproduce**:

```python
import modin.pandas as pd
left = pd.DataFrame([[1]], index=[0])
right = pd.DataFrame([[2], [3]], index=[1, 1])
pd.merge_asof(left, right, on=0)
```

### Describe the problem
`merge_asof` with duplicated index raises `ValueError` in a remote function. We reindex the right frame with labels of rows that join to rows in the left, but reindexing a frame that has a non-unique index is never allowed. When the right frame has duplicates, we get `ValueError`.

The snippet above works if you replace `modin.pandas` with `pandas`.

### Source code / logs
Stack trace from a ray task:

<details>
<summary> Stack trace</summary>

```
RayTaskError(ValueError): ray::deploy_ray_func() (pid=67170, ip=127.0.0.1)
  File "/Users/maheshvashishtha/software_sources/modin/modin/core/execution/ray/implementations/pandas_on_ray/partitioning/virtual_partition.py", line 532, in deploy_ray_func
    result = func(*args, **kwargs)
  File "/Users/maheshvashishtha/software_sources/modin/modin/core/dataframe/pandas/partitioning/axis_partition.py", line 162, in deploy_axis_func
    result = func(dataframe, *kwargs.pop("args", ()), **kwargs)
  File "/Users/maheshvashishtha/software_sources/modin/modin/core/dataframe/pandas/dataframe/dataframe.py", line 1393, in _tree_reduce_func
    series_result = func(df, *args, **kwargs)
  File "/Users/maheshvashishtha/software_sources/modin/modin/core/storage_formats/pandas/query_compiler.py", line 517, in <lambda>
    lambda df: df.reindex(labels=labels, axis=axis, **kwargs),
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/util/_decorators.py", line 324, in wrapper
    return func(*args, **kwargs)
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/frame.py", line 4804, in reindex
    return super().reindex(**kwargs)
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/generic.py", line 4966, in reindex
    return self._reindex_axes(
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/frame.py", line 4623, in _reindex_axes
    frame = frame._reindex_index(
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/frame.py", line 4642, in _reindex_index
    return self._reindex_with_indexers(
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/generic.py", line 5032, in _reindex_with_indexers
    new_data = new_data.reindex_indexer(
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/internals/managers.py", line 679, in reindex_indexer
    self.axes[axis]._validate_can_reindex(indexer)
  File "/Users/maheshvashishtha/opt/anaconda3/envs/modin-latest/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 4107, in _validate_can_reindex
    raise ValueError("cannot reindex on an axis with duplicate labels")
ValueError: cannot reindex on an axis with duplicate labels
```

</details>



Discussion:

Resolving patch:
diff --git a/modin/pandas/general.py b/modin/pandas/general.py
--- a/modin/pandas/general.py
+++ b/modin/pandas/general.py
@@ -194,6 +194,11 @@ def merge_asof(
         or not isinstance(by, (str, type(None)))
         or not isinstance(left_by, (str, type(None)))
         or not isinstance(right_by, (str, type(None)))
+        # The implementation below assumes that the right index is unique
+        # because it uses merge_asof to map each position in the merged
+        # index to the label of the one right row that should be merged
+        # at that row position.
+        or not right.index.is_unique
     ):
         if isinstance(right, DataFrame):
             right = to_pandas(right)


Test patch:
diff --git a/modin/pandas/test/test_general.py b/modin/pandas/test/test_general.py
--- a/modin/pandas/test/test_general.py
+++ b/modin/pandas/test/test_general.py
@@ -201,9 +201,12 @@ def test_merge_ordered():
         pd.merge_ordered(data_a, data_b, fill_method="ffill", left_by="group")
 
 
-def test_merge_asof():
+@pytest.mark.parametrize("right_index", [None, [0] * 5], ids=["default", "non_unique"])
+def test_merge_asof(right_index):
     left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]})
-    right = pd.DataFrame({"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]})
+    right = pd.DataFrame(
+        {"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]}, index=right_index
+    )
 
     with warns_that_defaulting_to_pandas():
         df = pd.merge_asof(left, right, on="a")