Repository: modin-project/modin

Issue:
raise TypeError("Cannot do operation non-numeric dtypes")
<!--
General questions should be asked on the mailing list modin-dev@googlegroups.com.

Before submitting an issue, please fill out the following form.
-->

### System information
- **OS Platform and Distribution:**  Linux Ubuntu 18.04
- **Modin installed from (source or binary)**: : pip3 install modin
- **Modin version**: 0.5.3
- **Python version**: 3.6.8
- **Exact command to reproduce**:
1- df_runFlag = pd.read_csv(Config.FX_GetJsonConfig()['RunFlagTablePath'], usecols=['Platform', 'RunFlag', 'RAI', 'IAI', 'OAI'], encoding = 'utf8')

2-  st_Platforms = df_runFlag.loc[df_runFlag['RunFlag'] == 1, 'Platform']


### Describe the problem
I have those two lines of code in separated files. Both including modin.pandas.
misc file have the line of code number 1.
main file have the line of code number 2.
On main file I am calling the a method on the misc file that will read the csv. The main file has modin.pandas all the time, and if on misc file (to read the csv) has pandas..everything will work but if I change to modin.pandas I get an error.

### Source code / logs
File "main.py", line 97, in <module>
    Fx_Initialization()
  File "main.py", line 47, in Fx_Initialization
    st_Platforms = df_runFlag.loc[df_runFlag['RunFlag'] == 1, 'Platform']
  File "/.local/lib/python3.6/site-packages/modin/pandas/indexing.py", line 241, in __getitem__
    if key[0] == slice(None):
  File "/.local/lib/python3.6/site-packages/modin/pandas/base.py", line 3158, in __eq__
    return self.eq(other)
  File "/.local/lib/python3.6/site-packages/modin/pandas/series.py", line 527, in eq
    return super(Series, new_self).eq(new_other, level=level, axis=axis)
  File "/.local/lib/python3.6/site-packages/modin/pandas/base.py", line 1037, in eq
    return self._binary_op("eq", other, axis=axis, level=level)
  File ".local/lib/python3.6/site-packages/modin/pandas/base.py", line 191, in _binary_op
    other = self._validate_other(other, axis, numeric_or_object_only=True)
  File "/.local/lib/python3.6/site-packages/modin/pandas/base.py", line 155, in _validate_other
    raise TypeError("Cannot do operation non-numeric dtypes")


What is causing this? 
Thank you in advance


Discussion:
Hi @techbrismo, thanks for posting!

It looks like our error checking is not matching pandas in this case. I will look into this a bit deeper.

Using multiple python files shouldn't cause any errors, so I don't think that is causing the problem. Thanks again for the report!

Resolving patch:
diff --git a/modin/pandas/indexing.py b/modin/pandas/indexing.py
--- a/modin/pandas/indexing.py
+++ b/modin/pandas/indexing.py
@@ -238,12 +238,17 @@ def __getitem__(self, key):
         else:
             if len(key) > self.df.ndim:
                 raise IndexingError("Too many indexers")
-            if key[0] == slice(None):
+            if isinstance(key[0], slice) and key[0] == slice(None):
                 return self.df.__getitem__(key[1])
         row_loc, col_loc, ndim, self.row_scaler, self.col_scaler = _parse_tuple(key)
         self._handle_enlargement(row_loc, col_loc)
         row_lookup, col_lookup = self._compute_lookup(row_loc, col_loc)
-        ndim = (0 if len(row_lookup) == 1 else 1) + (0 if len(col_lookup) == 1 else 1)
+        # Check that the row_lookup/col_lookup is longer than 1 or that the
+        # row_loc/col_loc is not boolean list to determine the ndim of the
+        # result properly for multiindex.
+        ndim = (0 if len(row_lookup) == 1 and not is_boolean_array(row_loc) else 1) + (
+            0 if len(col_lookup) == 1 and not is_boolean_array(col_loc) else 1
+        )
         result = super(_LocIndexer, self).__getitem__(row_lookup, col_lookup, ndim)
         # Pandas drops the levels that are in the `loc`, so we have to as well.
         if hasattr(result, "index") and isinstance(result.index, pandas.MultiIndex):
@@ -338,6 +343,9 @@ def _compute_lookup(self, row_loc, col_loc):
             )
         elif isinstance(self.qc.index, pandas.MultiIndex):
             row_lookup = self.qc.index.get_locs(row_loc)
+        elif is_boolean_array(row_loc):
+            # If passed in a list of booleans, we return the index of the true values
+            row_lookup = [i for i, row_val in enumerate(row_loc) if row_val]
         else:
             row_lookup = self.qc.index.get_indexer_for(row_loc)
         if isinstance(col_loc, slice):
@@ -346,6 +354,9 @@ def _compute_lookup(self, row_loc, col_loc):
             )
         elif isinstance(self.qc.columns, pandas.MultiIndex):
             col_lookup = self.qc.columns.get_locs(col_loc)
+        elif is_boolean_array(col_loc):
+            # If passed in a list of booleans, we return the index of the true values
+            col_lookup = [i for i, col_val in enumerate(col_loc) if col_val]
         else:
             col_lookup = self.qc.columns.get_indexer_for(col_loc)
         return row_lookup, col_lookup


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
@@ -2910,6 +2910,17 @@ def test_loc(self, request, data):
             # DataFrame
             df_equals(modin_df.loc[[1, 2]], pandas_df.loc[[1, 2]])
 
+            # List-like of booleans
+            indices = [
+                True if i % 3 == 0 else False for i in range(len(modin_df.index))
+            ]
+            columns = [
+                True if i % 5 == 0 else False for i in range(len(modin_df.columns))
+            ]
+            modin_result = modin_df.loc[indices, columns]
+            pandas_result = pandas_df.loc[indices, columns]
+            df_equals(modin_result, pandas_result)
+
             # See issue #80
             # df_equals(modin_df.loc[[1, 2], ['col1']], pandas_df.loc[[1, 2], ['col1']])
             df_equals(modin_df.loc[1:2, key1:key2], pandas_df.loc[1:2, key1:key2])
diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py
--- a/modin/pandas/test/test_series.py
+++ b/modin/pandas/test/test_series.py
@@ -1704,6 +1704,11 @@ def test_loc(data):
         df_equals(modin_series.loc[v], pandas_series.loc[v])
         df_equals(modin_series.loc[v:], pandas_series.loc[v:])
 
+    indices = [True if i % 3 == 0 else False for i in range(len(modin_series.index))]
+    modin_result = modin_series.loc[indices]
+    pandas_result = pandas_series.loc[indices]
+    df_equals(modin_result, pandas_result)
+
 
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
 def test_lt(data):