Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX-#1556: Fix support for nested assignment with loc/iloc #1788

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ def _validate_dtypes_min_max(self, axis, numeric_only):
def _validate_dtypes(self, numeric_only=False):
pass

def _update_inplace(self, new_query_compiler):
super(Series, self)._update_inplace(new_query_compiler=new_query_compiler)
# Propagate changes back to parent so that column in dataframe had the same contents
if self._parent is not None:
if self._parent_axis == 0:
self._parent.loc[self.name] = self
else:
self._parent[self.name] = self

def _create_or_update_from_compiler(self, new_query_compiler, inplace=False):
"""Returns or updates a DataFrame given new query_compiler"""
assert (
Expand Down Expand Up @@ -329,12 +338,6 @@ def __setitem__(self, key, value):
self._create_or_update_from_compiler(
self._query_compiler.setitem(1, key, value), inplace=True
)
# Propagate changes back to parent so that column in dataframe had the same contents
if self._parent is not None:
if self._parent_axis == 0:
self._parent.loc[self.name] = self
else:
self._parent[self.name] = self

def __sub__(self, right):
return self.sub(right)
Expand Down
30 changes: 30 additions & 0 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4581,6 +4581,21 @@ def test_loc_assignment(self):
pandas_df.loc["row3"]["col2"] = 32
df_equals(modin_df, pandas_df)

@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_loc_nested_assignment(self, data):
modin_df = pd.DataFrame(data)
pandas_df = pandas.DataFrame(data)
key1 = modin_df.columns[0]
key2 = modin_df.columns[1]

modin_df[key1].loc[0] = 500
pandas_df[key1].loc[0] = 500
df_equals(modin_df, pandas_df)

modin_df[key2].loc[0] = None
pandas_df[key2].loc[0] = None
df_equals(modin_df, pandas_df)

def test_iloc_assignment(self):
modin_df = pd.DataFrame(
index=["row1", "row2", "row3"], columns=["col1", "col2"]
Expand All @@ -4602,6 +4617,21 @@ def test_iloc_assignment(self):
pandas_df.iloc[2]["col2"] = 32
df_equals(modin_df, pandas_df)

@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_iloc_nested_assignment(self, data):
modin_df = pd.DataFrame(data)
pandas_df = pandas.DataFrame(data)
key1 = modin_df.columns[0]
key2 = modin_df.columns[1]

modin_df[key1].iloc[0] = 500
pandas_df[key1].iloc[0] = 500
df_equals(modin_df, pandas_df)

modin_df[key2].iloc[0] = None
pandas_df[key2].iloc[0] = None
df_equals(modin_df, pandas_df)

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