Beispiel #1
0
def _make_time_bins(axis, freq, begin=None, end=None,
                    closed='right', label='right'):
    assert(isinstance(axis, DatetimeIndex))

    if len(axis) == 0:
        # TODO: Should we be a bit more careful here?
        return [], [], []

    first, last = _get_range_edges(axis, begin, end, freq, closed=closed)
    binner = DatetimeIndex(freq=freq, start=first, end=last)

    # a little hack
    trimmed = False
    if len(binner) > 2 and binner[-2] == axis[-1]:
        binner = binner[:-1]
        trimmed = True

    # general version, knowing nothing about relative frequencies
    bins = lib.generate_bins_dt64(axis.asi8, binner.asi8, closed)

    if label == 'right':
        labels = binner[1:]
    elif not trimmed:
        labels = binner[:-1]
    else:
        labels = binner

    return binner, bins, labels
Beispiel #2
0
    def _get_time_bins(self, axis):
        assert(isinstance(axis, DatetimeIndex))

        if len(axis) == 0:
            binner = labels = DatetimeIndex(data=[], freq=self.freq)
            return binner, [], labels

        first, last = _get_range_edges(axis, self.begin, self.end, self.freq,
                                       closed=self.closed, base=self.base)
        binner = DatetimeIndex(freq=self.freq, start=first, end=last)

        # a little hack
        trimmed = False
        if len(binner) > 2 and binner[-2] == axis[-1]:
            binner = binner[:-1]
            trimmed = True

        # general version, knowing nothing about relative frequencies
        bins = lib.generate_bins_dt64(axis.asi8, binner.asi8, self.closed)

        if self.label == 'right':
            labels = binner[1:]
        elif not trimmed:
            labels = binner[:-1]
        else:
            labels = binner

        return binner, bins, labels
Beispiel #3
0
    def _group_timestamps(self):
        if self.kind is None or self.kind == 'timestamp':
            binner = self._generate_time_binner()

            # a little hack
            trimmed = False
            if len(binner) > 2 and binner[-2] == self.axis[-1]:
                binner = binner[:-1]
                trimmed = True

            # general version, knowing nothing about relative frequencies
            bins = lib.generate_bins_dt64(self.axis.asi8, binner.asi8,
                                          self.closed)

            if self.label == 'right':
                labels = binner[1:]
            elif not trimmed:
                labels = binner[:-1]
            else:
                labels = binner

            return binner, bins, labels
        elif self.kind == 'period':
            index = PeriodIndex(start=self.axis[0], end=self.axis[-1],
                                freq=self.offset)

            end_stamps = (index + 1).asfreq('D', 's').to_timestamp()
            bins = self.axis.searchsorted(end_stamps, side='left')

            return index, bins, index