# Buggy code
def _downsample(self, how, **kwargs):
    """
    Downsample the cython defined function

    Parameters
    ----------
    how : string / cython mapped function
    **kwargs : kw args passed to how function
    """

    # we may need to actually resample as if we are timestamps
    if self.kind == "timestamp":
        return super(PeriodIndexResampler, self)._downsample(how, **kwargs)

    how = self._is_cython_func(how) or how
    ax = self.ax

    new_index = self._get_new_index()
    if len(new_index) == 0:
        return self._wrap_result(new_index)

    # Start vs. end of period
    memb = ax.asfreq(self.freq, how=self.convention)

    if is_subperiod(ax.freq, self.freq):
        # Downsampling
        rng = np.arange(memb.values[0], memb.values[-1] + 1)
        bins = memb.searchsorted(rng, side="right")
        grouper = BinGrouper(bins, new_index)
        return self._groupby_and_aggregate(grouper, how)
    elif is_superperiod(ax.freq, self.freq):
        return self.asfreq()

    raise ValueError(
        "Frequency {axfreq} cannot be resampled to {freq}".format(
            axfreq=ax.freq, freq=self.freq
        )
    )


# Traceback (TypeError)
In [38]: pd.Series(1, index=pd.period_range(start='2000', periods=100)).resample('M').count()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-295afa97781f> in <module>()
----> 1 pd.Series(1, index=pd.period_range(start='2000', periods=100)).resample('M').count()

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in f(self, _method)
473
474     def f(self, _method=method):
--> 475         return self._groupby_and_aggregate(None, _method)
476     f.__doc__ = getattr(GroupBy, method).__doc__
477     setattr(Resampler, method, f)

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _groupby_and_aggregate(self, grouper, how, *args, **kwargs)
353
354         if grouper is None:
--> 355             self._set_binner()
356             grouper = self.grouper
357

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _set_binner(self)
202
203         if self.binner is None:
--> 204             self.binner, self.grouper = self._get_binner()
205
206     def _get_binner(self):

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _get_binner(self)
210         """
211
--> 212         binner, bins, binlabels = self._get_binner_for_time()
213         bin_grouper = BinGrouper(bins, binlabels)
214         return binner, bin_grouper

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _get_binner_for_time(self)
538         if self.kind == 'period':
539             return self.groupby._get_time_period_bins(self.ax)
--> 540         return self.groupby._get_time_bins(self.ax)
541
542     def _downsample(self, how, **kwargs):

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/tseries/resample.py in _get_time_bins(self, ax)
905         if not isinstance(ax, DatetimeIndex):
906             raise TypeError('axis must be a DatetimeIndex, but got '
--> 907                             'an instance of %r' % type(ax).__name__)
908
909         if len(ax) == 0:

TypeError: axis must be a DatetimeIndex, but got an instance of 'PeriodIndex'

# Fixed code
def _downsample(self, how, **kwargs):
    """
    Downsample the cython defined function

    Parameters
    ----------
    how : string / cython mapped function
    **kwargs : kw args passed to how function
    """

    # we may need to actually resample as if we are timestamps
    if self.kind == "timestamp":
        return super(PeriodIndexResampler, self)._downsample(how, **kwargs)

    how = self._is_cython_func(how) or how
    ax = self.ax

    new_index = self._get_new_index()
    if len(new_index) == 0:
        return self._wrap_result(self._selected_obj.reindex(new_index))

    # Start vs. end of period
    memb = ax.asfreq(self.freq, how=self.convention)

    if is_subperiod(ax.freq, self.freq):
        # Downsampling
        rng = np.arange(memb.values[0], memb.values[-1] + 1)
        bins = memb.searchsorted(rng, side="right")
        grouper = BinGrouper(bins, new_index)
        return self._groupby_and_aggregate(grouper, how)
    elif is_superperiod(ax.freq, self.freq):
        return self.asfreq()
    elif ax.freq == self.freq:
        return self.asfreq()

    raise ValueError(
        "Frequency {axfreq} cannot be resampled to {freq}".format(
            axfreq=ax.freq, freq=self.freq
        )
    )