sidpy/base/num_utils.py
def integers_to_slices(int_array):
    """
    Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers

    Parameters
    ----------
    int_array : :class:`collections.Iterable`
        iterable object like a :class:`list` or :class:`numpy.ndarray`

    Returns
    -------
    sequences : list
        List of :class:`slice` objects each denoting sequences of consecutive numbers
    """
    if not contains_integers(int_array):
        raise ValueError('Expected a list, tuple, or numpy array of integers')

    def integers_to_consecutive_sections(integer_array):
        """
        Converts a sequence of iterables to tuples with start and stop bounds

        @author: @juanchopanza and @luca from stackoverflow

        Parameters
        ----------
        integer_array : :class:`collections.Iterable`
            iterable object like a :class:`list`

        Returns
        -------
        iterable : :class:`generator`
            Cast to list or similar to use

        Note
        ----
        From https://stackoverflow.com/questions/4628333/converting-a-list-of-integers-into-range-in-python
        """
        integer_array = sorted(set(integer_array))
        for key, group in groupby(enumerate(integer_array),
                                  lambda t: t[1] - t[0]):
            group = list(group)
            yield group[0][1], group[-1][1]

    sequences = [slice(item[0], item[1] + 1) for item in integers_to_consecutive_sections(int_array)]
    return sequences

    Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers

    Parameters
    ----------
    int_array : :class:`collections.Iterable`
        iterable object like a :class:`list` or :class:`numpy.ndarray`

    Returns
    -------
    sequences : list
        List of :class:`slice` objects each denoting sequences of consecutive numbers
    
Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers
Parameters



Returns

sequences : list
List of :class:`slice` objects each denoting sequences of consecutive numbers
Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers Parameters Returns sequences : list List of : class : ` slice ` objects each denoting sequences of consecutive numbers
def integers_to_slices(int_array):
    if not contains_integers(int_array):
        raise ValueError('Expected a list, tuple, or numpy array of integers')
    def integers_to_consecutive_sections(integer_array):
        integer_array = sorted(set(integer_array))
        for key, group in groupby(enumerate(integer_array),
                                  lambda t: t[1] - t[0]):
            group = list(group)
            yield group[0][1], group[-1][1]
    sequences = [slice(item[0], item[1] + 1) for item in integers_to_consecutive_sections(int_array)]
    return sequences
def integers_to_slices ( int_array ) : if not contains_integers ( int_array ) : raise ValueError ( 'Expected a list, tuple, or numpy array of integers' ) def integers_to_consecutive_sections ( integer_array ) : """
        Converts a sequence of iterables to tuples with start and stop bounds

        @author: @juanchopanza and @luca from stackoverflow

        Parameters
        ----------
        integer_array : :class:`collections.Iterable`
            iterable object like a :class:`list`

        Returns
        -------
        iterable : :class:`generator`
            Cast to list or similar to use

        Note
        ----
        From https://stackoverflow.com/questions/4628333/converting-a-list-of-integers-into-range-in-python
        """ integer_array = sorted ( set ( integer_array ) ) for key , group in groupby ( enumerate ( integer_array ) , lambda t : t [ 1 ] - t [ 0 ] ) : group = list ( group ) yield group [ 0 ] [ 1 ] , group [ - 1 ] [ 1 ] sequences = [ slice ( item [ 0 ] , item [ 1 ] + 1 ) for item in integers_to_consecutive_sections ( int_array ) ] return sequences
Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers
Parameters
Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers Parameters
"""
    Converts a sequence of iterables to a list of slice objects denoting sequences of consecutive numbers

    Parameters
    ----------
    int_array : :class:`collections.Iterable`
        iterable object like a :class:`list` or :class:`numpy.ndarray`

    Returns
    -------
    sequences : list
        List of :class:`slice` objects each denoting sequences of consecutive numbers
    """ """
        Converts a sequence of iterables to tuples with start and stop bounds

        @author: @juanchopanza and @luca from stackoverflow

        Parameters
        ----------
        integer_array : :class:`collections.Iterable`
            iterable object like a :class:`list`

        Returns
        -------
        iterable : :class:`generator`
            Cast to list or similar to use

        Note
        ----
        From https://stackoverflow.com/questions/4628333/converting-a-list-of-integers-into-range-in-python
        """
int_array