code: def _set_tz(values, tz, preserve_UTC=False, coerce=False):
      
      if tz is not None:
          name = getattr(values, 'name', None)
          values = values.ravel()
          tz = timezones.get_timezone(_ensure_decoded(tz))
          values = DatetimeIndex(values, name=name)
          if values.tz is None:
              values = values.tz_localize('UTC').tz_convert(tz)
          if preserve_UTC:
              if tz == 'UTC':
                  values = list(values)
      elif coerce:
          values = np.asarray(values, dtype='M8[ns]')
  
      return values
docs: 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