# Buggy code
def __setitem__(self, key, value):
    if not isinstance(key, str):
        return self._default_to_pandas(pandas.DataFrame.__setitem__, key, value)
    if key not in self.columns:
        self.insert(loc=len(self.columns), column=key, value=value)
    else:
        loc = self.columns.get_loc(key)
        self.__delitem__(key)
        self.insert(loc=loc, column=key, value=value)


# Traceback (AssertionError)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-5-7f2184cfd6d7> in <module>
2 df = pd.DataFrame(columns=cols)
3 for col in cols:
----> 4     df[col] = np.arange(10)

~/Documents/modin/modin/pandas/dataframe.py in __setitem__(self, key, value)
4605         else:
4606             loc = self.columns.get_loc(key)
-> 4607             self.__delitem__(key)
4608             self.insert(loc=loc, column=key, value=value)
4609

~/Documents/modin/modin/pandas/dataframe.py in __delitem__(self, key)
4690         if key not in self:
4691             raise KeyError(key)
-> 4692         self._update_inplace(new_query_compiler=self._query_compiler.delitem(key))
4693
4694     def __finalize__(self, other, method=None, **kwargs):

~/Documents/modin/modin/data_management/query_compiler/pandas_query_compiler.py in delitem(self, key)
2294     # These will change the shape of the resulting data.
2295     def delitem(self, key):
-> 2296         return self.drop(columns=[key])
2297
2298     def drop(self, index=None, columns=None):

~/Documents/modin/modin/data_management/query_compiler/pandas_query_compiler.py in drop(self, index, columns)
2336             new_columns = self.columns[~self.columns.isin(columns)]
2337             new_dtypes = self.dtypes.drop(columns)
-> 2338         return self.__constructor__(new_data, new_index, new_columns, new_dtypes)
2339
2340     # END __delitem__ and drop

~/Documents/modin/modin/data_management/query_compiler/pandas_query_compiler.py in __constructor__(self, block_paritions_object, index, columns, dtypes)
41     def __constructor__(self, block_paritions_object, index, columns, dtypes=None):
42         """By default, constructor method will invoke an init"""
---> 43         return type(self)(block_paritions_object, index, columns, dtypes)
44
45     # Index, columns and dtypes objects

~/Documents/modin/modin/data_management/query_compiler/pandas_query_compiler.py in __init__(self, block_partitions_object, index, columns, dtypes)
32         dtypes=None,
33     ):
---> 34         assert isinstance(block_partitions_object, BaseBlockPartitions)
35         self.data = block_partitions_object
36         self.index = index

AssertionError:

# Fixed code
def __setitem__(self, key, value):
    if not isinstance(key, str):

        def setitem_without_string_columns(df):
            df[key] = value
            return df

        return self._update_inplace(
            self._default_to_pandas(setitem_without_string_columns)._query_compiler
        )
    if key not in self.columns:
        self.insert(loc=len(self.columns), column=key, value=value)
    elif len(self.index) == 0:
        new_self = DataFrame({key: value}, columns=self.columns)
        self._update_inplace(new_self._query_compiler)
    else:
        self._update_inplace(self._query_compiler.setitem(key, value))