# Buggy code
def _get_time_bins(self, ax):
    if not isinstance(ax, DatetimeIndex):
        raise TypeError(
            "axis must be a DatetimeIndex, but got "
            "an instance of %r" % type(ax).__name__
        )

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

    first, last = ax.min(), ax.max()
    first, last = _get_range_edges(
        first, last, self.freq, closed=self.closed, base=self.base
    )
    tz = ax.tz
    binner = labels = DatetimeIndex(
        freq=self.freq,
        start=first.replace(tzinfo=None),
        end=last.replace(tzinfo=None),
        tz=tz,
        name=ax.name,
    )

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

    ax_values = ax.asi8
    binner, bin_edges = self._adjust_bin_edges(binner, ax_values)

    # general version, knowing nothing about relative frequencies
    bins = lib.generate_bins_dt64(ax_values, bin_edges, self.closed, hasnans=ax.hasnans)

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

    if ax.hasnans:
        binner = binner.insert(0, tslib.NaT)
        labels = labels.insert(0, tslib.NaT)

    # if we end up with more labels than bins
    # adjust the labels
    # GH4076
    if len(bins) < len(labels):
        labels = labels[: len(bins)]

    return binner, bins, labels


# Traceback (ValueError)
4.035752
4035751999

ValueError                                Traceback (most recent call last)
<ipython-input-14-92e377227823> in <module>()
5     period_nanos=int(period_seconds*(10**9))
6     print period_nanos
----> 7     res= dfi.value.resample(pd.tseries.offsets.Nano(period_nanos), how=[np.min, np.max,'mean'])
8
9     nullrows=pd.isnull(res).any(1).nonzero()[0]

C:\Users\USER1\Anaconda2\lib\site-packages\pandas\core\generic.pyc in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base)
3641                               fill_method=fill_method, convention=convention,
3642                               limit=limit, base=base)
-> 3643         return sampler.resample(self).__finalize__(self)
3644
3645     def first(self, offset):

C:\Users\USER1\Anaconda2\lib\site-packages\pandas\tseries\resample.pyc in resample(self, obj)
80
81         if isinstance(ax, DatetimeIndex):
---> 82             rs = self._resample_timestamps()
83         elif isinstance(ax, PeriodIndex):
84             offset = to_offset(self.freq)

C:\Users\USER1\Anaconda2\lib\site-packages\pandas\tseries\resample.pyc in _resample_timestamps(self, kind)
274         axlabels = self.ax
275
--> 276         self._get_binner_for_resample(kind=kind)
277         grouper = self.grouper
278         binner = self.binner

C:\Users\USER1\Anaconda2\lib\site-packages\pandas\tseries\resample.pyc in _get_binner_for_resample(self, kind)
118             kind = self.kind
119         if kind is None or kind == 'timestamp':
--> 120             self.binner, bins, binlabels = self._get_time_bins(ax)
121         elif kind == 'timedelta':
122             self.binner, bins, binlabels = self._get_time_delta_bins(ax)

C:\Users\USER1\Anaconda2\lib\site-packages\pandas\tseries\resample.pyc in _get_time_bins(self, ax)
179
180         # general version, knowing nothing about relative frequencies
--> 181         bins = lib.generate_bins_dt64(ax_values, bin_edges, self.closed, hasnans=ax.hasnans)
182
183         if self.closed == 'right':

pandas\lib.pyx in pandas.lib.generate_bins_dt64 (pandas\lib.c:20875)()

ValueError: Values falls after last bin

# Fixed code
def _get_time_bins(self, ax):
    if not isinstance(ax, DatetimeIndex):
        raise TypeError(
            "axis must be a DatetimeIndex, but got "
            "an instance of %r" % type(ax).__name__
        )

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

    first, last = ax.min(), ax.max()
    first, last = _get_range_edges(
        first, last, self.freq, closed=self.closed, base=self.base
    )
    tz = ax.tz
    # GH #12037
    # use first/last directly instead of call replace() on them
    # because replace() will swallow the nanosecond part
    # thus last bin maybe slightly before the end if the end contains
    # nanosecond part and lead to `Values falls after last bin` error
    binner = labels = DatetimeIndex(
        freq=self.freq, start=first, end=last, tz=tz, name=ax.name
    )

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

    ax_values = ax.asi8
    binner, bin_edges = self._adjust_bin_edges(binner, ax_values)

    # general version, knowing nothing about relative frequencies
    bins = lib.generate_bins_dt64(ax_values, bin_edges, self.closed, hasnans=ax.hasnans)

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

    if ax.hasnans:
        binner = binner.insert(0, tslib.NaT)
        labels = labels.insert(0, tslib.NaT)

    # if we end up with more labels than bins
    # adjust the labels
    # GH4076
    if len(bins) < len(labels):
        labels = labels[: len(bins)]

    return binner, bins, labels