Skip to content

Commit

Permalink
fix #465 to_datetime now returns a pd.Timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Oct 28, 2024
1 parent f77c0f7 commit 1459c80
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/traffic/core/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
_log = logging.getLogger(__name__)


def to_datetime(time: timelike) -> datetime:
def to_datetime(time: timelike) -> pd.Timestamp:
"""Facility to convert anything to a datetime.
This function will soon be replaced by pd.to_datetime.
Expand All @@ -41,10 +41,10 @@ def to_datetime(time: timelike) -> datetime:

if isinstance(time, str):
time = pd.Timestamp(time, tz="utc")
if isinstance(time, pd.Timestamp):
time = time.to_pydatetime()
if isinstance(time, datetime):
time = pd.Timestamp(time)
if isinstance(time, Real):
time = datetime.fromtimestamp(float(time), timezone.utc)
time = pd.Timestamp(float(time), tz="utc", unit="s")
if time.tzinfo is None: # coverage: ignore
_log.warning(
"This timestamp is tz-naive. Things may not work as expected. "
Expand Down

0 comments on commit 1459c80

Please sign in to comment.