Repository: modin-project/modin

Issue:
Issue with SetItem for DataFrame (doesn't persist with stock pandas)
System information
OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
Modin version (modin.__version__): 0.10.1
Python version: 3.7.9 Intel Corporation
Code we can use to reproduce: please contact alyssa.unell@intel.com for more information on the code and the dataset
train[label_names] = (train[label_names] > 0) * 1


Describe the problem
Modin implementation of pandas breaks with setItem, doesn't break with stock pandas

Source code / logs
Please contact alyssa.unell@intel.com for more information on the code and dataset.
UserWarning: `DataFrame.setitem_unhashable_key` defaulting to pandas implementation.
To request implementation, send an email to feature_requests@modin.org.
Traceback (most recent call last):
  File "deeplearning/RecSys2020/02_ModelsCompetition/XGBoost2/sub040_1_save_public.py", line 724, in <module>
    train[label_names] = (train[label_names] > 0) * 1
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/modin/pandas/dataframe.py", line 2540, in __setitem__
    self._default_to_pandas(setitem_unhashable_key)._query_compiler
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/modin/pandas/base.py", line 459, in _default_to_pandas
    result = op(pandas_obj, *args, **kwargs)
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/modin/pandas/dataframe.py", line 2536, in setitem_unhashable_key
    df[key] = value
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/pandas/core/frame.py", line 3597, in __setitem__
    self._setitem_array(key, value)
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/pandas/core/frame.py", line 3648, in _setitem_array
    return self._setitem_array(key, value)
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/pandas/core/frame.py", line 3643, in _setitem_array
    self._iset_not_inplace(key, value)
  File "/localdisk/alyssa/anaconda3/envs/aikit-modin/lib/python3.7/site-packages/pandas/core/frame.py", line 3670, in _iset_not_inplace
    raise ValueError("Columns must be same length as key")



Discussion:

Resolving patch:
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -2542,15 +2542,12 @@ def __setitem__(self, key, value):
                     key = DataFrame(key, columns=self.columns)
                 return self.mask(key, value, inplace=True)
 
-            def setitem_unhashable_key(df):
-                # Arrow makes memory-mapped objects immutable, so copy will allow them
-                # to be mutable again.
-                df = df.copy(True)
+            def setitem_unhashable_key(df, value):
                 df[key] = value
                 return df
 
             return self._update_inplace(
-                self._default_to_pandas(setitem_unhashable_key)._query_compiler
+                self._default_to_pandas(setitem_unhashable_key, value)._query_compiler
             )
         if is_list_like(value):
             if isinstance(value, (pandas.DataFrame, DataFrame)):


Test patch:
diff --git a/modin/pandas/test/dataframe/test_indexing.py b/modin/pandas/test/dataframe/test_indexing.py
--- a/modin/pandas/test/dataframe/test_indexing.py
+++ b/modin/pandas/test/dataframe/test_indexing.py
@@ -1616,6 +1616,16 @@ def applyier(df):
     eval_general(modin_df, pandas_df, applyier)
 
 
+def test___setitem__unhashable_list():
+    # from #3258 and #3291
+    cols = ["a", "b"]
+    modin_df = pd.DataFrame([[0, 0]], columns=cols)
+    modin_df[cols] = modin_df[cols]
+    pandas_df = pandas.DataFrame([[0, 0]], columns=cols)
+    pandas_df[cols] = pandas_df[cols]
+    df_equals(modin_df, pandas_df)
+
+
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
 def test___len__(data):
     modin_df = pd.DataFrame(data)