# Buggy code
def sort_rows(self, columns, ascending, ignore_index, na_position):
    if na_position != "first" and na_position != "last":
        raise ValueError(f"Unsupported na_position value '{na_position}'")

    if not isinstance(columns, list):
        columns = [columns]

    for col in columns:
        if col not in self._table_cols:
            raise ValueError(f"Unknown column '{col}'")

    if isinstance(ascending, list):
        if len(ascending) != len(columns):
            raise ValueError("ascending list length doesn't match columns list")
    else:
        if not isinstance(ascending, bool):
            raise ValueError("unsupported ascending value")
        ascending = [ascending] * len(columns)

    if ignore_index:
        # If index is ignored then we might need to drop some columns.
        # At the same time some of dropped index columns can be used
        # for sorting and should be droped after sorting is done.
        if self._index_cols is not None:
            base = self

            drop_index_cols_before = [
                col for col in self._index_cols if col not in columns
            ]
            drop_index_cols_after = [col for col in self._index_cols if col in columns]
            if not drop_index_cols_after:
                drop_index_cols_after = None

            if drop_index_cols_before:
                exprs = OrderedDict()
                index_cols = drop_index_cols_after if drop_index_cols_after else None
                for col in drop_index_cols_after:
                    exprs[col] = base.ref(col)
                for col in base.columns:
                    exprs[col] = base.ref(col)
                base = self.__constructor__(
                    columns=base.columns,
                    dtypes=self._dtypes_for_exprs(exprs),
                    op=TransformNode(base, exprs),
                    index_cols=index_cols,
                    force_execution_mode=self._force_execution_mode,
                )

            base = self.__constructor__(
                columns=base.columns,
                dtypes=base._dtypes,
                op=SortNode(base, columns, ascending, na_position),
                index_cols=base._index_cols,
                force_execution_mode=self._force_execution_mode,
            )

            if drop_index_cols_after:
                exprs = OrderedDict()
                for col in base.columns:
                    exprs[col] = base.ref(col)
                base = self.__constructor__(
                    columns=base.columns,
                    dtypes=self._dtypes_for_exprs(exprs),
                    op=TransformNode(base, exprs),
                    index_cols=None,
                    force_execution_mode=self._force_execution_mode,
                )

            return base
        else:
            return self.__constructor__(
                columns=self.columns,
                dtypes=self._dtypes,
                op=SortNode(self, columns, ascending, na_position),
                index_cols=None,
                force_execution_mode=self._force_execution_mode,
            )
    else:
        base = self

        # If index is preserved and we have no index columns then we
        # need to create one using __rowid__ virtual column.
        if self._index_cols is None:
            base = base._materialize_rowid()

        return self.__constructor__(
            columns=base.columns,
            dtypes=base._dtypes,
            op=SortNode(base, columns, ascending, na_position),
            index_cols=base._index_cols,
            force_execution_mode=self._force_execution_mode,
        )


# 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 sort_rows(self, columns, ascending, ignore_index, na_position):
    if na_position != "first" and na_position != "last":
        raise ValueError(f"Unsupported na_position value '{na_position}'")

    if not isinstance(columns, list):
        columns = [columns]
    columns = [self._find_index_or_col(col) for col in columns]

    if isinstance(ascending, list):
        if len(ascending) != len(columns):
            raise ValueError("ascending list length doesn't match columns list")
    else:
        if not isinstance(ascending, bool):
            raise ValueError("unsupported ascending value")
        ascending = [ascending] * len(columns)

    if ignore_index:
        # If index is ignored then we might need to drop some columns.
        # At the same time some of dropped index columns can be used
        # for sorting and should be droped after sorting is done.
        if self._index_cols is not None:
            base = self

            drop_index_cols_before = [
                col for col in self._index_cols if col not in columns
            ]
            drop_index_cols_after = [col for col in self._index_cols if col in columns]
            if not drop_index_cols_after:
                drop_index_cols_after = None

            if drop_index_cols_before:
                exprs = OrderedDict()
                index_cols = drop_index_cols_after if drop_index_cols_after else None
                for col in drop_index_cols_after:
                    exprs[col] = base.ref(col)
                for col in base.columns:
                    exprs[col] = base.ref(col)
                base = self.__constructor__(
                    columns=base.columns,
                    dtypes=self._dtypes_for_exprs(exprs),
                    op=TransformNode(base, exprs),
                    index_cols=index_cols,
                    force_execution_mode=self._force_execution_mode,
                )

            base = self.__constructor__(
                columns=base.columns,
                dtypes=base._dtypes,
                op=SortNode(base, columns, ascending, na_position),
                index_cols=base._index_cols,
                force_execution_mode=self._force_execution_mode,
            )

            if drop_index_cols_after:
                exprs = OrderedDict()
                for col in base.columns:
                    exprs[col] = base.ref(col)
                base = self.__constructor__(
                    columns=base.columns,
                    dtypes=self._dtypes_for_exprs(exprs),
                    op=TransformNode(base, exprs),
                    index_cols=None,
                    force_execution_mode=self._force_execution_mode,
                )

            return base
        else:
            return self.__constructor__(
                columns=self.columns,
                dtypes=self._dtypes,
                op=SortNode(self, columns, ascending, na_position),
                index_cols=None,
                force_execution_mode=self._force_execution_mode,
            )
    else:
        base = self

        # If index is preserved and we have no index columns then we
        # need to create one using __rowid__ virtual column.
        if self._index_cols is None:
            base = base._materialize_rowid()

        return self.__constructor__(
            columns=base.columns,
            dtypes=base._dtypes,
            op=SortNode(base, columns, ascending, na_position),
            index_cols=base._index_cols,
            force_execution_mode=self._force_execution_mode,
        )