from sklearn import model_selection as ms
import pandas as pd

def train_test_split(*args, keep_index:bool=False, **kwargs):
    """Split arrays or matrices into random train and test subsets

    Modified version ("wrapper") which resets indices on Pandas DataFrames automatically, 
    using df.reset_index(drop=True); so make sure your index doesn't contain 
    something keepworthy - in that case use the original train_test_split
    or specify keep_index=True

    Read more in the :ref:`User Guide <cross_validation>`.

    Parameters
    ----------
    *arrays : sequence of indexables with same length / shape[0]
        Allowed inputs are lists, numpy arrays, scipy-sparse
        matrices or pandas dataframes.

    test_size : float or int, default=None
        If float, should be between 0.0 and 1.0 and represent the proportion
        of the dataset to include in the test split. If int, represents the
        absolute number of test samples. If None, the value is set to the
        complement of the train size. If ``train_size`` is also None, it will
        be set to 0.25.

    keep_index : bool, default=False
        Instead of dropping the index, keep it (i.e.) use
        unchanged sklearn.model_selection.train_test_split()

    train_size : float or int, default=None
        If float, should be between 0.0 and 1.0 and represent the
        proportion of the dataset to include in the train split. If
        int, represents the absolute number of train samples. If None,
        the value is automatically set to the complement of the test size.

    random_state : int or RandomState instance, default=None
        Controls the shuffling applied to the data before applying the split.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.


    shuffle : bool, default=True
        Whether or not to shuffle the data before splitting. If shuffle=False
        then stratify must be None.

    stratify : array-like, default=None
        If not None, data is split in a stratified fashion, using this as
        the class labels.

    Returns
    -------
    splitting : list, length=2 * len(arrays)
        List containing train-test split of inputs.

        .. versionadded:: 0.16
            If the input is sparse, the output will be a
            ``scipy.sparse.csr_matrix``. Else, output type is the same as the
            input type.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.model_selection import train_test_split
    >>> X, y = np.arange(10).reshape((5, 2)), range(5)
    >>> X
    array([[0, 1],
           [2, 3],
           [4, 5],
           [6, 7],
           [8, 9]])
    >>> list(y)
    [0, 1, 2, 3, 4]

    >>> X_train, X_test, y_train, y_test = train_test_split(
    ...     X, y, test_size=0.33, random_state=42)
    ...
    >>> X_train
    array([[4, 5],
           [0, 1],
           [6, 7]])
    >>> y_train
    [2, 0, 3]
    >>> X_test
    array([[2, 3],
           [8, 9]])
    >>> y_test
    [1, 4]

    >>> train_test_split(y, shuffle=False)
    [[0, 1, 2], [3, 4]]

    """
    if keep_index:
        return ms.train_test_split(*args, **kwargs)
    return (a.reset_index(drop=True) if isinstance(a, pd.core.frame.DataFrame) else a for a in ms.train_test_split(*args, **kwargs) )
from sklearn import model_selection as ms
import pandas as pd

def train_test_split(*args, keep_index:bool=False, **kwargs):
    """Split arrays or matrices into random train and test subsets

    Modified version ("wrapper") which resets indices on Pandas DataFrames automatically, 
    using df.reset_index(drop=True); so make sure your index doesn't contain 
    something keepworthy - in that case use the original train_test_split
    or specify keep_index=True

    Read more in the :ref:`User Guide <cross_validation>`.

    Parameters
    ----------
    *arrays : sequence of indexables with same length / shape[0]
        Allowed inputs are lists, numpy arrays, scipy-sparse
        matrices or pandas dataframes.

    test_size : float or int, default=None
        If float, should be between 0.0 and 1.0 and represent the proportion
        of the dataset to include in the test split. If int, represents the
        absolute number of test samples. If None, the value is set to the
        complement of the train size. If ``train_size`` is also None, it will
        be set to 0.25.

    keep_index : bool, default=False
        Instead of dropping the index, keep it (i.e.) use
        unchanged sklearn.model_selection.train_test_split()

    train_size : float or int, default=None
        If float, should be between 0.0 and 1.0 and represent the
        proportion of the dataset to include in the train split. If
        int, represents the absolute number of train samples. If None,
        the value is automatically set to the complement of the test size.

    random_state : int or RandomState instance, default=None
        Controls the shuffling applied to the data before applying the split.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.


    shuffle : bool, default=True
        Whether or not to shuffle the data before splitting. If shuffle=False
        then stratify must be None.

    stratify : array-like, default=None
        If not None, data is split in a stratified fashion, using this as
        the class labels.

    Returns
    -------
    splitting : list, length=2 * len(arrays)
        List containing train-test split of inputs.

        .. versionadded:: 0.16
            If the input is sparse, the output will be a
            ``scipy.sparse.csr_matrix``. Else, output type is the same as the
            input type.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.model_selection import train_test_split
    >>> X, y = np.arange(10).reshape((5, 2)), range(5)
    >>> X
    array([[0, 1],
           [2, 3],
           [4, 5],
           [6, 7],
           [8, 9]])
    >>> list(y)
    [0, 1, 2, 3, 4]

    >>> X_train, X_test, y_train, y_test = train_test_split(
    ...     X, y, test_size=0.33, random_state=42)
    ...
    >>> X_train
    array([[4, 5],
           [0, 1],
           [6, 7]])
    >>> y_train
    [2, 0, 3]
    >>> X_test
    array([[2, 3],
           [8, 9]])
    >>> y_test
    [1, 4]

    >>> train_test_split(y, shuffle=False)
    [[0, 1, 2], [3, 4]]

    """
    if keep_index:
        return ms.train_test_split(*args, **kwargs)
    return (a.reset_index(drop=True) if isinstance(a, pd.core.frame.DataFrame) else a for a in ms.train_test_split(*args, **kwargs) )
Split arrays or matrices into random train and test subsets      Modified version ("wrapper") which resets indices on Pandas DataFrames automatically,      using df.reset_index(drop=True); so make sure your index doesn't contain      something keepworthy - in that case use the original train_test_split     or specify keep_index=True      Read more in the :ref:`User Guide <cross_validation>`.      Parameters     ----------     *arrays : sequence of indexables with same length / shape[0]         Allowed inputs are lists, numpy arrays, scipy-sparse         matrices or pandas dataframes.      test_size : float or int, default=None         If float, should be between 0.0 and 1.0 and represent the proportion         of the dataset to include in the test split. If int, represents the         absolute number of test samples. If None, the value is set to the         complement of the train size. If ``train_size`` is also None, it will         be set to 0.25.      keep_index : bool, default=False         Instead of dropping the index, keep it (i.e.) use         unchanged sklearn.model_selection.train_test_split()      train_size : float or int, default=None         If float, should be between 0.0 and 1.0 and represent the         proportion of the dataset to include in the train split. If         int, represents the absolute number of train samples. If None,         the value is automatically set to the complement of the test size.      random_state : int or RandomState instance, default=None         Controls the shuffling applied to the data before applying the split.         Pass an int for reproducible output across multiple function calls.         See :term:`Glossary <random_state>`.       shuffle : bool, default=True         Whether or not to shuffle the data before splitting. If shuffle=False         then stratify must be None.      stratify : array-like, default=None         If not None, data is split in a stratified fashion, using this as         the class labels.      Returns     -------     splitting : list, length=2 * len(arrays)         List containing train-test split of inputs.          .. versionadded:: 0.16             If the input is sparse, the output will be a             ``scipy.sparse.csr_matrix``. Else, output type is the same as the             input type.      Examples     --------     >>> import numpy as np     >>> from sklearn.model_selection import train_test_split     >>> X, y = np.arange(10).reshape((5, 2)), range(5)     >>> X     array([[0, 1],            [2, 3],            [4, 5],            [6, 7],            [8, 9]])     >>> list(y)     [0, 1, 2, 3, 4]      >>> X_train, X_test, y_train, y_test = train_test_split(     ...     X, y, test_size=0.33, random_state=42)     ...     >>> X_train     array([[4, 5],            [0, 1],            [6, 7]])     >>> y_train     [2, 0, 3]     >>> X_test     array([[2, 3],            [8, 9]])     >>> y_test     [1, 4]      >>> train_test_split(y, shuffle=False)     [[0, 1, 2], [3, 4]]