def shift(self, periods, fill_value=None):
<EOL>codes = self.codes<EOL>if codes.ndim > <NUM_LIT:1>:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>if np.prod(codes.shape) and (periods != <NUM_LIT:0>):<EOL><INDENT>codes = np.roll(codes, ensure_platform_int(periods), axis=<NUM_LIT:0>)<EOL>if isna(fill_value):<EOL><INDENT>fill_value = -<NUM_LIT:1><EOL><DEDENT>elif fill_value in self.categories:<EOL><INDENT>fill_value = self.categories.get_loc(fill_value)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(fill_value))<EOL><DEDENT>if periods > <NUM_LIT:0>:<EOL><INDENT>codes[:periods] = fill_value<EOL><DEDENT>else:<EOL><INDENT>codes[periods:] = fill_value<EOL><DEDENT><DEDENT>return self.from_codes(codes, dtype=self.dtype)<EOL>
Shift Categorical by desired number of periods.

Parameters
----------
periods : int
    Number of periods to move, can be positive or negative
fill_value : object, optional
    The scalar value to use for newly introduced missing values.

    .. versionadded:: 0.24.0

Returns
-------
shifted : Categorical