Skip to content

Instantly share code, notes, and snippets.

@prateekiiest
Last active March 25, 2018 13:42
Show Gist options
  • Save prateekiiest/5ee9b91c42f9a896316970536d4553bb to your computer and use it in GitHub Desktop.
Save prateekiiest/5ee9b91c42f9a896316970536d4553bb to your computer and use it in GitHub Desktop.
This table shows the modifications that needs to be done in parse_time to return Time objects instead of Datetime objects

First importing import astropy.time as t

Input instances for time_string Current working of parse_time Proposed changes to return astropy.Time
astropy.Time return time_string.datetime return time_string
now return datetime.utcnow() return t.Time.now()
pandas.Timeseries return time_string.to_pydatetime() return t.Time(time_string)
isinstance(time_string, pandas.Series) and 'datetime64' in str(time_string.dtype) return np.array([dt.to_pydatetime() for dt in time_string]) return np.array([t.Time(dt) for dt in time_string])
datetime return time_string return t.Time(time_string)
tuple return datetime(*time_string) if time = (2018,10,3,10,43,5,6) see code here
date return datetime.combine(time_string, time()) return t.Time(datetime.combine(time_string, time()))
pandas.DatetimeIndex return time_string._mpl_repr() if time_string = DatetimeIndex(np.array([1,2,34])) return [t.Time(t[tim]) for tim in range(len(time_string))]
np.datetime64 return _parse_dt64(time_string) return _parse_dt64_Time(time_string) with modified version of _parse_dt64 discussed later
date return datetime.combine(time_string, time()) See Enhancement
time_format = utime and time_string = <int, float> return datetime(1979, 1, 1) + timedelta(0, time_string) See Enhancement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment