diff --git a/modin/pandas/indexing.py b/modin/pandas/indexing.py index f076e3cddc6..0b3c3d872e0 100644 --- a/modin/pandas/indexing.py +++ b/modin/pandas/indexing.py @@ -339,7 +339,10 @@ def _compute_lookup(self, row_loc, col_loc): self.qc.index.to_series().loc[row_loc] ) elif isinstance(self.qc.index, pandas.MultiIndex): - row_lookup = self.qc.index.get_locs(row_loc) + if isinstance(row_loc, pandas.MultiIndex): + row_lookup = self.qc.index.get_indexer_for(row_loc) + else: + 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] @@ -350,7 +353,10 @@ def _compute_lookup(self, row_loc, col_loc): self.qc.columns.to_series().loc[col_loc] ) elif isinstance(self.qc.columns, pandas.MultiIndex): - col_lookup = self.qc.columns.get_locs(col_loc) + if isinstance(col_loc, pandas.MultiIndex): + col_lookup = self.qc.columns.get_indexer_for(col_loc) + else: + 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] diff --git a/modin/pandas/test/test_dataframe.py b/modin/pandas/test/test_dataframe.py index b1798eb553f..7ef6cfe8a6f 100644 --- a/modin/pandas/test/test_dataframe.py +++ b/modin/pandas/test/test_dataframe.py @@ -4584,6 +4584,10 @@ def test_loc_multi_index(self): transposed_pandas.loc[transposed_pandas.index[:-2], :], ) + # From issue #1610 + df_equals(modin_df.loc[modin_df.index], pandas_df.loc[pandas_df.index]) + df_equals(modin_df.loc[modin_df.index[:7]], pandas_df.loc[pandas_df.index[:7]]) + def test_loc_assignment(self): modin_df = pd.DataFrame( index=["row1", "row2", "row3"], columns=["col1", "col2"]