def diff(arr, n, axis=<NUM_LIT:0>):
n = int(n)<EOL>na = np.nan<EOL>dtype = arr.dtype<EOL>is_timedelta = False<EOL>if needs_i8_conversion(arr):<EOL><INDENT>dtype = np.float64<EOL>arr = arr.view('<STR_LIT>')<EOL>na = iNaT<EOL>is_timedelta = True<EOL><DEDENT>elif is_bool_dtype(dtype):<EOL><INDENT>dtype = np.object_<EOL><DEDENT>elif is_integer_dtype(dtype):<EOL><INDENT>dtype = np.float64<EOL><DEDENT>dtype = np.dtype(dtype)<EOL>out_arr = np.empty(arr.shape, dtype=dtype)<EOL>na_indexer = [slice(None)] * arr.ndim<EOL>na_indexer[axis] = slice(None, n) if n >= <NUM_LIT:0> else slice(n, None)<EOL>out_arr[tuple(na_indexer)] = na<EOL>if arr.ndim == <NUM_LIT:2> and arr.dtype.name in _diff_special:<EOL><INDENT>f = _diff_special[arr.dtype.name]<EOL>f(arr, out_arr, n, axis)<EOL><DEDENT>else:<EOL><INDENT>res_indexer = [slice(None)] * arr.ndim<EOL>res_indexer[axis] = slice(n, None) if n >= <NUM_LIT:0> else slice(None, n)<EOL>res_indexer = tuple(res_indexer)<EOL>lag_indexer = [slice(None)] * arr.ndim<EOL>lag_indexer[axis] = slice(None, -n) if n > <NUM_LIT:0> else slice(-n, None)<EOL>lag_indexer = tuple(lag_indexer)<EOL>if is_timedelta:<EOL><INDENT>res = arr[res_indexer]<EOL>lag = arr[lag_indexer]<EOL>mask = (arr[res_indexer] == na) | (arr[lag_indexer] == na)<EOL>if mask.any():<EOL><INDENT>res = res.copy()<EOL>res[mask] = <NUM_LIT:0><EOL>lag = lag.copy()<EOL>lag[mask] = <NUM_LIT:0><EOL><DEDENT>result = res - lag<EOL>result[mask] = na<EOL>out_arr[res_indexer] = result<EOL><DEDENT>else:<EOL><INDENT>out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer]<EOL><DEDENT><DEDENT>if is_timedelta:<EOL><INDENT>from pandas import TimedeltaIndex<EOL>out_arr = TimedeltaIndex(out_arr.ravel().astype('<STR_LIT>')).asi8.reshape(<EOL>out_arr.shape).astype('<STR_LIT>')<EOL><DEDENT>return out_arr<EOL>
difference of n between self,
analogous to s-s.shift(n)

Parameters
----------
arr : ndarray
n : int
    number of periods
axis : int
    axis to shift on

Returns
-------
shifted