<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def partial_transform(self, sequence, mode='clip'):
 """Transform a sequence to internal indexing Recall that `sequence` can be arbitrary labels, whereas ``transmat_`` and ``countsmat_`` are indexed with integers between 0 and ``n_states - 1``. This methods maps a set of sequences from the labels onto this internal indexing. Parameters sequence : array-like A 1D iterable of state labels. Labels can be integers, strings, or other orderable objects. mode : {'clip', 'fill'} Method by which to treat labels in `sequence` which do not have a corresponding index. This can be due, for example, to the ergodic trimming step. ``clip`` Unmapped labels are removed during transform. If they occur at the beginning or end of a sequence, the resulting transformed sequence will be shorted. If they occur in the middle of a sequence, that sequence will be broken into two (or more) sequences. (Default) ``fill`` Unmapped labels will be replaced with NaN, to signal missing data. [The use of NaN to signal missing data is not fantastic, but it's consistent with current behavior of the ``pandas`` library.] Returns ------- mapped_sequence : list or ndarray If mode is "fill", return an ndarray in internal indexing. If mode is "clip", return a list of ndarrays each in internal indexing. """

        if mode not in ['clip', 'fill']:
            raise ValueError('mode must be one of ["clip", "fill"]: %s' % mode)
        sequence = np.asarray(sequence)
        if sequence.ndim != 1:
            raise ValueError("Each sequence must be 1D")

        f = np.vectorize(lambda k: self.mapping_.get(k, np.nan),
                         otypes=[np.float])

        a = f(sequence)
        if mode == 'fill':
            if np.all(np.mod(a, 1) == 0):
                result = a.astype(int)
            else:
                result = a
        elif mode == 'clip':
            result = [a[s].astype(int) for s in
                      np.ma.clump_unmasked(np.ma.masked_invalid(a))]
        else:
            raise RuntimeError()

        return result