From 36106b42eb0d731545be53f23ce6a2a7f6f1bc46 Mon Sep 17 00:00:00 2001 From: ienkovich Date: Fri, 21 Aug 2020 11:32:49 +0300 Subject: [PATCH] REFACTOR-#1938: avoid index access in a simple column reference (#1939) Signed-off-by: ienkovich --- modin/pandas/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modin/pandas/base.py b/modin/pandas/base.py index bd2f693246f..14d908553e4 100644 --- a/modin/pandas/base.py +++ b/modin/pandas/base.py @@ -3442,9 +3442,14 @@ def __getitem__(self, key): return self._default_to_pandas("__getitem__", key) # see if we can slice the rows # This lets us reuse code in Pandas to error check - indexer = convert_to_index_sliceable( - getattr(pandas, type(self).__name__)(index=self.index), key - ) + indexer = None + if isinstance(key, slice) or ( + isinstance(key, str) + and (not hasattr(self, "columns") or key not in self.columns) + ): + indexer = convert_to_index_sliceable( + getattr(pandas, type(self).__name__)(index=self.index), key + ) if indexer is not None: return self._getitem_slice(indexer) else: