Repository: modin-project/modin

Issue:
`loc` with slice throws TypeError

### Describe the problem
<!-- Describe the problem clearly here. -->
When using a `slice` with `loc`, I see a TypeError get thrown. See logs below.

### Source code / logs
<!-- 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. -->
```
In [4]: df.loc[:, "col0":"col3"]                                                                                                             
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-f1d9690a44cf> in <module>
----> 1 df.loc[:, "col0":"col3"]

~/software_builds/modin/modin/pandas/indexing.py in __getitem__(self, key)
    213                 raise IndexingError("Too many indexers")
    214             if isinstance(key[0], slice) and key[0] == slice(None):
--> 215                 return self.df.__getitem__(key[1])
    216         row_loc, col_loc, ndim, self.row_scaler, self.col_scaler = _parse_tuple(key)
    217         row_lookup, col_lookup = self._compute_lookup(row_loc, col_loc)

~/software_builds/modin/modin/pandas/base.py in __getitem__(self, key)
   3284         # This lets us reuse code in Pandas to error check
   3285         indexer = convert_to_index_sliceable(
-> 3286             getattr(pandas, self.__name__)(index=self.index), key
   3287         )
   3288         if indexer is not None:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py in convert_to_index_sliceable(obj, key)
   2356     idx = obj.index
   2357     if isinstance(key, slice):
-> 2358         return idx._convert_slice_indexer(key, kind="getitem")
   2359 
   2360     elif isinstance(key, str):

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexes/base.py in _convert_slice_indexer(self, key, kind)
   3188             if self.is_integer() or is_index_slice:
   3189                 return slice(
-> 3190                     self._validate_indexer("slice", key.start, kind),
   3191                     self._validate_indexer("slice", key.stop, kind),
   3192                     self._validate_indexer("slice", key.step, kind),

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexes/base.py in _validate_indexer(self, form, key, kind)
   5069             pass
   5070         elif kind in ["iloc", "getitem"]:
-> 5071             self._invalid_indexer(form, key)
   5072         return key
   5073 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexes/base.py in _invalid_indexer(self, form, key)
   3338             "cannot do {form} indexing on {klass} with these "
   3339             "indexers [{key}] of {kind}".format(
-> 3340                 form=form, klass=type(self), key=key, kind=type(key)
   3341             )
   3342         )

TypeError: cannot do slice indexing on <class 'pandas.core.indexes.range.RangeIndex'> with these indexers [col0] of <class 'str'>
```


Discussion:

Resolving patch:
diff --git a/modin/pandas/indexing.py b/modin/pandas/indexing.py
--- a/modin/pandas/indexing.py
+++ b/modin/pandas/indexing.py
@@ -212,7 +212,11 @@ def __getitem__(self, key):
             if len(key) > self.df.ndim:
                 raise IndexingError("Too many indexers")
             if isinstance(key[0], slice) and key[0] == slice(None):
-                return self.df.__getitem__(key[1])
+                if not isinstance(key[1], slice):
+                    return self.df.__getitem__(key[1])
+                else:
+                    result_slice = self.df.columns.slice_locs(key[1].start, key[1].stop)
+                    return self.df.iloc[:, slice(*result_slice)]
         row_loc, col_loc, ndim, self.row_scaler, self.col_scaler = _parse_tuple(key)
         row_lookup, col_lookup = self._compute_lookup(row_loc, col_loc)
         # Check that the row_lookup/col_lookup is longer than 1 or that the


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
@@ -4414,6 +4414,11 @@ def test_loc(self, request, data):
             df_equals(modin_df.loc[:, [key2, key1]], pandas_df.loc[:, [key2, key1]])
             df_equals(modin_df.loc[[2, 1], :], pandas_df.loc[[2, 1], :])
 
+            # From issue #1023
+            key1 = modin_df.columns[0]
+            key2 = modin_df.columns[-2]
+            df_equals(modin_df.loc[:, key1:key2], pandas_df.loc[:, key1:key2])
+
             # Write Item
             modin_df_copy = modin_df.copy()
             pandas_df_copy = pandas_df.copy()