Skip to content

Commit

Permalink
FIX-modin-project#1679: Assignment df.loc["row"]["col"] fixed in case…
Browse files Browse the repository at this point in the history
… of one row (modin-project#1951)

Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
  • Loading branch information
dchigarev authored and aregm committed Sep 16, 2020
1 parent 035a29e commit 70c1278
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
4 changes: 4 additions & 0 deletions modin/engines/base/frame/partition_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def concat(cls, axis, left_parts, right_parts):
A new BaseFrameManager object, the type of object that called this.
"""
if type(right_parts) is list:
# `np.array` with partitions of empty ModinFrame has a shape (0,)
# but `np.concatenate` can concatenate arrays only if its shapes at
# specified axis are equals, so filtering empty frames to avoid concat error
right_parts = [o for o in right_parts if o.size != 0]
return np.concatenate([left_parts] + right_parts, axis=axis)
else:
return np.append(left_parts, right_parts, axis=axis)
Expand Down
30 changes: 10 additions & 20 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4677,26 +4677,16 @@ def test_loc_multi_index(self):
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"]
)
pandas_df = pandas.DataFrame(
index=["row1", "row2", "row3"], columns=["col1", "col2"]
)
modin_df.loc["row1"]["col1"] = 11
modin_df.loc["row2"]["col1"] = 21
modin_df.loc["row3"]["col1"] = 31
modin_df.loc["row1"]["col2"] = 12
modin_df.loc["row2"]["col2"] = 22
modin_df.loc["row3"]["col2"] = 32
pandas_df.loc["row1"]["col1"] = 11
pandas_df.loc["row2"]["col1"] = 21
pandas_df.loc["row3"]["col1"] = 31
pandas_df.loc["row1"]["col2"] = 12
pandas_df.loc["row2"]["col2"] = 22
pandas_df.loc["row3"]["col2"] = 32
df_equals(modin_df, pandas_df)
@pytest.mark.parametrize("index", [["row1", "row2", "row3"], ["row1"]])
@pytest.mark.parametrize("columns", [["col1", "col2"], ["col1"]])
def test_loc_assignment(self, index, columns):
md_df, pd_df = create_test_dfs(index=index, columns=columns)
for i, ind in enumerate(index):
for j, col in enumerate(columns):
value_to_assign = int(str(i) + str(j))
md_df.loc[ind][col] = value_to_assign
pd_df.loc[ind][col] = value_to_assign
df_equals(md_df, pd_df)

@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_loc_nested_assignment(self, data):
Expand Down

0 comments on commit 70c1278

Please sign in to comment.