def localize_to_utc(time, location):
if isinstance(time, dt.datetime):<EOL><INDENT>if time.tzinfo is None:<EOL><INDENT>time = pytz.timezone(location.tz).localize(time)<EOL><DEDENT>time_utc = time.astimezone(pytz.utc)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>time_utc = time.tz_convert('<STR_LIT>')<EOL><DEDENT>except TypeError:<EOL><INDENT>time_utc = time.tz_localize(location.tz).tz_convert('<STR_LIT>')<EOL><DEDENT><DEDENT>return time_utc<EOL>
Converts or localizes a time series to UTC.

Parameters
----------
time : datetime.datetime, pandas.DatetimeIndex,
       or pandas.Series/DataFrame with a DatetimeIndex.
location : pvlib.Location object

Returns
-------
pandas object localized to UTC.