def _time_shift(self, periods, freq=None):
if freq is not None and freq != self.freq:<EOL><INDENT>if isinstance(freq, str):<EOL><INDENT>freq = frequencies.to_offset(freq)<EOL><DEDENT>offset = periods * freq<EOL>result = self + offset<EOL>return result<EOL><DEDENT>if periods == <NUM_LIT:0>:<EOL><INDENT>return self.copy()<EOL><DEDENT>if self.freq is None:<EOL><INDENT>raise NullFrequencyError("<STR_LIT>")<EOL><DEDENT>start = self[<NUM_LIT:0>] + periods * self.freq<EOL>end = self[-<NUM_LIT:1>] + periods * self.freq<EOL>return self._generate_range(start=start, end=end, periods=None,<EOL>freq=self.freq)<EOL>
Shift each value by `periods`.

Note this is different from ExtensionArray.shift, which
shifts the *position* of each element, padding the end with
missing values.

Parameters
----------
periods : int
    Number of periods to shift by.
freq : pandas.DateOffset, pandas.Timedelta, or string
    Frequency increment to shift by.