def _set_tz(values, tz, preserve_UTC=False, coerce=False):
if tz is not None:<EOL><INDENT>name = getattr(values, '<STR_LIT:name>', None)<EOL>values = values.ravel()<EOL>tz = timezones.get_timezone(_ensure_decoded(tz))<EOL>values = DatetimeIndex(values, name=name)<EOL>if values.tz is None:<EOL><INDENT>values = values.tz_localize('<STR_LIT>').tz_convert(tz)<EOL><DEDENT>if preserve_UTC:<EOL><INDENT>if tz == '<STR_LIT>':<EOL><INDENT>values = list(values)<EOL><DEDENT><DEDENT><DEDENT>elif coerce:<EOL><INDENT>values = np.asarray(values, dtype='<STR_LIT>')<EOL><DEDENT>return values<EOL>
coerce the values to a DatetimeIndex if tz is set
preserve the input shape if possible

Parameters
----------
values : ndarray
tz : string/pickled tz object
preserve_UTC : boolean,
    preserve the UTC of the result
coerce : if we do not have a passed timezone, coerce to M8[ns] ndarray