# Buggy code
def _make_indexable(iterable):
    """Ensure iterable supports indexing or convert to an indexable variant.

    Convert sparse matrices to csr and other non-indexable iterable to arrays.
    Let `None` and indexable objects (e.g. pandas dataframes) pass unchanged.

    Parameters
    ----------
    iterable : {list, dataframe, array, sparse} or None
        Object to be converted to an indexable iterable.
    """
    if issparse(iterable):
        return mt.tensor(iterable)
    elif hasattr(iterable, "iloc"):
        return md.DataFrame(iterable)
    elif hasattr(iterable, "__getitem__"):
        return mt.tensor(iterable)
    elif iterable is None:
        return iterable
    return mt.tensor(iterable)


# Traceback (ValueError)
In [1]: import mars.dataframe as md

In [8]: X = df[['userId', 'rating']]

In [9]: y = df['movieId']

In [11]: train_test_split(X, y, train_size=0.7, random_state=0)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-94d1aec833af> in <module>
----> 1 train_test_split(X, y, train_size=0.7, random_state=0)

~/Workspace/mars/mars/learn/model_selection/_split.py in train_test_split(*arrays, **options)
112         raise TypeError(f"Invalid parameters passed: {options}")
113
--> 114     arrays = indexable(*arrays, session=session, run_kwargs=run_kwargs)
115
116     n_samples = _num_samples(arrays[0])

~/Workspace/mars/mars/learn/utils/validation.py in indexable(session, run_kwargs, *iterables)
139         List of objects to ensure sliceability.
140     """
--> 141     result = [_make_indexable(X) for X in iterables]
142     check_consistent_length(*result, session=session,
143                             run_kwargs=run_kwargs)

~/Workspace/mars/mars/learn/utils/validation.py in <listcomp>(.0)
139         List of objects to ensure sliceability.
140     """
--> 141     result = [_make_indexable(X) for X in iterables]
142     check_consistent_length(*result, session=session,
143                             run_kwargs=run_kwargs)

~/Workspace/mars/mars/learn/utils/validation.py in _make_indexable(iterable)
119         return mt.tensor(iterable)
120     elif hasattr(iterable, "iloc"):
--> 121         return md.DataFrame(iterable)
122     elif hasattr(iterable, "__getitem__"):
123         return mt.tensor(iterable)

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
55                                            columns=columns, gpu=gpu, sparse=sparse)
56         else:
---> 57             pdf = pd.DataFrame(data, index=index, columns=columns, dtype=dtype, copy=copy)
58             df = from_pandas_df(pdf, chunk_size=chunk_size, gpu=gpu, sparse=sparse)
59         super().__init__(df.data)

~/miniconda3/lib/python3.7/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
527         else:
528             if index is None or columns is None:
--> 529                 raise ValueError("DataFrame constructor not properly called!")
530
531             if not dtype:

ValueError: DataFrame constructor not properly called!

# Fixed code
def _make_indexable(iterable):
    """Ensure iterable supports indexing or convert to an indexable variant.

    Convert sparse matrices to csr and other non-indexable iterable to arrays.
    Let `None` and indexable objects (e.g. pandas dataframes) pass unchanged.

    Parameters
    ----------
    iterable : {list, dataframe, array, sparse} or None
        Object to be converted to an indexable iterable.
    """
    if issparse(iterable):
        return mt.tensor(iterable)
    elif hasattr(iterable, "iloc"):
        if iterable.ndim == 1:
            return md.Series(iterable)
        else:
            return md.DataFrame(iterable)
    elif hasattr(iterable, "__getitem__"):
        return mt.tensor(iterable)
    elif iterable is None:
        return iterable
    return mt.tensor(iterable)