# Buggy code
def from_pandas(cls, df):
    new_index = df.index
    new_columns = df.columns
    # If there is non-trivial index, we put it into columns.
    # That's what we usually have for arrow tables and execution
    # result. Unnamed index is renamed to __index__. Also all
    # columns get 'F_' prefix to handle names unsupported in
    # OmniSci.
    if cls._is_trivial_index(df.index):
        index_cols = None
    else:
        orig_index_names = df.index.names
        orig_df = df

        index_cols = ["__index__" if n is None else n for n in df.index.names]
        df.index.names = index_cols
        df = df.reset_index()

        orig_df.index.names = orig_index_names
    new_dtypes = df.dtypes
    df = df.add_prefix("F_")
    new_parts, new_lengths, new_widths = cls._frame_mgr_cls.from_pandas(df, True)
    return cls(
        new_parts,
        new_index,
        new_columns,
        new_lengths,
        new_widths,
        dtypes=new_dtypes,
        index_cols=index_cols,
    )


# Traceback (ValueError)
Traceback (most recent call last):
File "../reproducer.py", line 15, in <module>
md_df = pd.DataFrame(data, index=mi_index)
File "/localdisk/dchigare/repos/modin_bp/modin/pandas/dataframe.py", line 142, in __init__
self._query_compiler = from_pandas(pandas_df)._query_compiler
File "/localdisk/dchigare/repos/modin_bp/modin/pandas/utils.py", line 37, in from_pandas
return DataFrame(query_compiler=EngineDispatcher.from_pandas(df))
File "/localdisk/dchigare/repos/modin_bp/modin/data_management/factories/dispatcher.py", line 97, in from_pandas
return cls.__engine._from_pandas(df)
File "/localdisk/dchigare/repos/modin_bp/modin/data_management/factories/factories.py", line 71, in _from_pandas
return cls.io_cls.from_pandas(df)
File "/localdisk/dchigare/repos/modin_bp/modin/engines/base/io/io.py", line 31, in from_pandas
return cls.query_compiler_cls.from_pandas(df, cls.frame_cls)
File "/localdisk/dchigare/repos/modin_bp/modin/experimental/backends/omnisci/query_compiler.py", line 42, in from_pandas
return cls(data_cls.from_pandas(df))
File "/localdisk/dchigare/repos/modin_bp/modin/experimental/engines/omnisci_on_ray/frame/data.py", line 1142, in from_pandas
df = df.reset_index()
File "/localdisk/dchigare/miniconda3/envs/modin_on_omnisci/lib/python3.7/site-packages/pandas/core/frame.py", line 4854, in reset_index
new_obj.insert(0, name, level_values)
File "/localdisk/dchigare/miniconda3/envs/modin_on_omnisci/lib/python3.7/site-packages/pandas/core/frame.py", line 3623, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File "/localdisk/dchigare/miniconda3/envs/modin_on_omnisci/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 1177, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert __index__, already exists

# Fixed code
def from_pandas(cls, df):
    new_index = df.index
    new_columns = df.columns
    # If there is non-trivial index, we put it into columns.
    # That's what we usually have for arrow tables and execution
    # result. Unnamed index is renamed to __index__. Also all
    # columns get 'F_' prefix to handle names unsupported in
    # OmniSci.
    if cls._is_trivial_index(df.index):
        index_cols = None
    else:
        orig_index_names = df.index.names
        orig_df = df

        index_cols = [
            f"__index__{i}_{'__None__' if n is None else n}"
            for i, n in enumerate(df.index.names)
        ]
        df.index.names = index_cols
        df = df.reset_index()

        orig_df.index.names = orig_index_names
    new_dtypes = df.dtypes
    df = df.add_prefix("F_")
    new_parts, new_lengths, new_widths = cls._frame_mgr_cls.from_pandas(df, True)
    return cls(
        new_parts,
        new_index,
        new_columns,
        new_lengths,
        new_widths,
        dtypes=new_dtypes,
        index_cols=index_cols,
    )