Repository: modin-project/modin

Issue:
Pickling Error when masking with all False values after concat


### Describe the problem
<!-- Describe the problem clearly here. -->
Originally discovered in #516, if we mask a DataFrame that was concatenated with all False values, cloudpickle throws `PicklingError: Could not pickle object as excessively deep recursion required.`

### Source code / logs
```python
import modin.pandas as pd

frames = list()
df1 = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
frames.append(df1)

df2 = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
frames.append(df2)

df3 = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
frames.append(df3)

data = pd.concat(frames)
data[[True for _ in data.index]]
```
It works in the normal case:

```python
df1[[False for _ in df1.index]]
```

<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->



Discussion:

Resolving patch:
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -1854,7 +1854,12 @@ def _getitem_array(self, key):
             # of indices, and RangeIndex will give us the exact indices of each boolean
             # requested.
             key = pandas.RangeIndex(len(self.index))[key]
-            return DataFrame(query_compiler=self._query_compiler.getitem_row_array(key))
+            if len(key):
+                return DataFrame(
+                    query_compiler=self._query_compiler.getitem_row_array(key)
+                )
+            else:
+                return DataFrame(columns=self.columns)
         else:
             if any(k not in self.columns for k in key):
                 raise KeyError(


Test patch:
diff --git a/modin/pandas/test/test_dataframe.py b/modin/pandas/test/test_dataframe.py
--- a/modin/pandas/test/test_dataframe.py
+++ b/modin/pandas/test/test_dataframe.py
@@ -4670,6 +4670,35 @@ def test___getitem__(self, request, data):
             pd_col = pandas_df[key]
             df_equals(pd_col, modin_col)
 
+    def test_getitem_empty_mask(self):
+        # modin-project/modin#517
+        modin_frames = []
+        pandas_frames = []
+        data1 = np.random.randint(0, 100, size=(100, 4))
+        mdf1 = pd.DataFrame(data1, columns=list("ABCD"))
+        pdf1 = pandas.DataFrame(data1, columns=list("ABCD"))
+        modin_frames.append(mdf1)
+        pandas_frames.append(pdf1)
+
+        data2 = np.random.randint(0, 100, size=(100, 4))
+        mdf2 = pd.DataFrame(data2, columns=list("ABCD"))
+        pdf2 = pandas.DataFrame(data2, columns=list("ABCD"))
+        modin_frames.append(mdf2)
+        pandas_frames.append(pdf2)
+
+        data3 = np.random.randint(0, 100, size=(100, 4))
+        mdf3 = pd.DataFrame(data3, columns=list("ABCD"))
+        pdf3 = pandas.DataFrame(data3, columns=list("ABCD"))
+        modin_frames.append(mdf3)
+        pandas_frames.append(pdf3)
+
+        modin_data = pd.concat(modin_frames)
+        pandas_data = pandas.concat(pandas_frames)
+        df_equals(
+            modin_data[[False for _ in modin_data.index]],
+            pandas_data[[False for _ in modin_data.index]],
+        )
+
     @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
     def test___getattr__(self, request, data):
         modin_df = pd.DataFrame(data)