Repository: modin-project/modin

Issue:
Values are getting set to NaN upon using boolean indexes
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Mac OS Monterey
- **Modin version** (`modin.__version__`): 0.12.0
- **Python version**: 3.7.6
- **Code we can use to reproduce**:

```python3
import modin.pandas as mpd  # ray
series = mpd.Series(["123456", None])
null_mask = series.isnull()
print(series[~null_mask].astype(int).astype(str))  # prints 123456 correctly
series[~null_mask]=series[~null_mask].astype(int).astype(str)
print(series)  # Values in series: NaN, None
```

### Describe the problem
Values getting set to NaN upon using boolean indexes



Discussion:
I've found a simpler example to reproduce the bug:

```python
import modin.pandas as pd

series = pd.Series(123)
series[:1] = pd.Series(123)
print(series)
# Series has one element with NaN instead of 123
```

For that example, I've found:

1. `value`, the right-hand side of the assignment, has the column name "\_\_reduced\_\_" replaced with 0 in the query compiler [here](https://github.com/modin-project/modin/blob/d8963a691958d34627e503c7a437adade4935aa8/modin/core/storage_formats/pandas/query_compiler.py#L2230).
1. the NaN appears on running [this line](https://github.com/modin-project/modin/blob/d8963a691958d34627e503c7a437adade4935aa8/modin/core/storage_formats/base/query_compiler.py#L2617), where the query compiler concatenates the empty `first_mask`, which is an empty dataframe with column name "\_\_reduced\_\_"  to `value`, which has a single row with index label 0 and column name 0 (integer), and `second_mask`, which is an empty dataframe with column name "\_\_reduced\_\_". If I replace the name of the column in `value` with "\_\_reduced\_\_" as follows instead of running that line:

```python
first_mask.concat(axis, [pd.Series(123, name="__reduced__")._query_compiler, second_mask], join=how, sort=False)
```
I get the correct result.

I see two points where we could fix the bug, but I don't understand whether either fix would be correct:

1. We could stop replacing the column name "\_\_reduced\_\_" with 0.
1. We could make the query compiler's `concat`stop assigning `NaN` when two dataframes with different column names are concatenated. But is that the correct behavior?

Resolving patch:
diff --git a/modin/pandas/indexing.py b/modin/pandas/indexing.py
--- a/modin/pandas/indexing.py
+++ b/modin/pandas/indexing.py
@@ -532,7 +532,9 @@ def get_axis(axis):
             for i, lookup in enumerate([row_lookup, col_lookup])
         ]
 
-        if (
+        if col_lookup_len == 1 and row_lookup_len == 1:
+            axis = None
+        elif (
             row_lookup_len == len(self.qc.index)
             and col_lookup_len == 1
             and isinstance(self.df, DataFrame)


Test patch:
diff --git a/modin/pandas/test/dataframe/test_indexing.py b/modin/pandas/test/dataframe/test_indexing.py
--- a/modin/pandas/test/dataframe/test_indexing.py
+++ b/modin/pandas/test/dataframe/test_indexing.py
@@ -1605,6 +1605,14 @@ def test___setitem__(data):
     pandas_df[1:5] = 10
     df_equals(modin_df, pandas_df)
 
+    # Test assigning a single item in a Series for issue
+    # https://github.com/modin-project/modin/issues/3860
+    modin_single_item_series = pd.Series(99)
+    pandas_single_item_series = pandas.Series(99)
+    modin_single_item_series[:1] = pd.Series(100)
+    pandas_single_item_series[:1] = pandas.Series(100)
+    df_equals(modin_single_item_series, pandas_single_item_series)
+
 
 def test___setitem__partitions_aligning():
     # from issue #2390