def shift(self, periods):
    '\n        Shift Categorical by desired number of periods.\n\n        Parameters\n        ----------\n        periods : int\n            Number of periods to move, can be positive or negative\n\n        Returns\n        -------\n        shifted : Categorical\n        '
    codes = self.codes
    if (codes.ndim > 1):
        raise NotImplementedError('Categorical with ndim > 1.')
    if (np.prod(codes.shape) and (periods != 0)):
        codes = np.roll(codes, ensure_platform_int(periods), axis=0)
        if (periods > 0):
            codes[:periods] = (- 1)
        else:
            codes[periods:] = (- 1)
    return self.from_codes(codes, categories=self.categories, ordered=self.ordered)
Shift Categorical by desired number of periods.

Parameters
----------
periods : int
    Number of periods to move, can be positive or negative

Returns
-------
shifted : Categorical
def shift(self, periods):
    '\n        Shift Categorical by desired number of periods.\n\n        Parameters\n        ----------\n        periods : int\n            Number of periods to move, can be positive or negative\n\n        Returns\n        -------\n        shifted : Categorical\n        '
    codes = self.codes
    if (codes.ndim > 1):
        raise NotImplementedError('Categorical with ndim > 1.')
    if (np.prod(codes.shape) and (periods != 0)):
        codes = np.roll(codes, ensure_platform_int(periods), axis=0)
        if (periods > 0):
            codes[:periods] = (- 1)
        else:
            codes[periods:] = (- 1)
    return self.from_codes(codes, categories=self.categories, ordered=self.ordered)