Skip to content

Commit

Permalink
FIX-modin-project#1610: Fix support for loc with MultiIndex paramet…
Browse files Browse the repository at this point in the history
…er (modin-project#1789)

Signed-off-by: Devin Petersohn <[email protected]>
  • Loading branch information
devin-petersohn authored and aregm committed Sep 16, 2020
1 parent 4696eeb commit c33d420
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit c33d420

Please sign in to comment.