Skip to content

Commit

Permalink
FIX-modin-project#4354: Fix df.loc on multiindex dataframe
Browse files Browse the repository at this point in the history
Signed-off-by: Naren Krishna <[email protected]>
  • Loading branch information
naren-ponder committed Jun 1, 2022
1 parent 3d4404e commit 3a37eb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ def __getitem__(self, key):
"""
if self.df.empty:
return self.df._default_to_pandas(lambda df: df.loc[key])
if isinstance(key, tuple):
loc_series = _LocIndexer(self.__getitem__(key[0])).__getitem__(key[1])
loc_series.name = (key[0], key[1])
return loc_series
row_loc, col_loc, ndim = self._parse_row_and_column_locators(key)
self.row_scalar = is_scalar(row_loc)
self.col_scalar = is_scalar(col_loc)
Expand Down
11 changes: 11 additions & 0 deletions modin/pandas/test/dataframe/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,17 @@ def test_iloc_assignment():
df_equals(modin_df, pandas_df)


def test_loc_multiple_arguments():
arrays = [
np.array(["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"]),
np.array(["one", "two", "one", "two", "one", "two", "one", "two"]),
]
values = np.random.randn(8, 4)
modin_df = pd.DataFrame(values, index=arrays)
pandas_df = pandas.DataFrame(values, index=arrays)
df_equals(modin_df.loc['bar', 'one'], pandas_df.loc['bar', 'one'])


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_iloc_nested_assignment(data):
modin_df = pd.DataFrame(data)
Expand Down

0 comments on commit 3a37eb4

Please sign in to comment.