def _wrap_results(result, dtype, fill_value=None):
if is_datetime64_dtype(dtype) or is_datetime64tz_dtype(dtype):<EOL><INDENT>if fill_value is None:<EOL><INDENT>fill_value = iNaT<EOL><DEDENT>if not isinstance(result, np.ndarray):<EOL><INDENT>tz = getattr(dtype, '<STR_LIT>', None)<EOL>assert not isna(fill_value), "<STR_LIT>"<EOL>if result == fill_value:<EOL><INDENT>result = np.nan<EOL><DEDENT>result = tslibs.Timestamp(result, tz=tz)<EOL><DEDENT>else:<EOL><INDENT>result = result.view(dtype)<EOL><DEDENT><DEDENT>elif is_timedelta64_dtype(dtype):<EOL><INDENT>if not isinstance(result, np.ndarray):<EOL><INDENT>if result == fill_value:<EOL><INDENT>result = np.nan<EOL><DEDENT>if np.fabs(result) > _int64_max:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>result = tslibs.Timedelta(result, unit='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>result = result.astype('<STR_LIT>').view(dtype)<EOL><DEDENT><DEDENT>return result<EOL>
wrap our results if needed