Skip to content

Commit

Permalink
Assume float timestamps are UTC.
Browse files Browse the repository at this point in the history
`time.time()` returns unix timestamp in utc, so this seems to be a
reasonable assumption.
  • Loading branch information
kgodlewski committed Dec 9, 2024
1 parent 1856e2e commit 89c5302
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/neptune_scale/api/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import itertools
import threading
import warnings
from datetime import datetime
from datetime import (
datetime,
timezone,
)
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -95,7 +98,7 @@ def log(
if timestamp is None:
timestamp = datetime.now()
elif isinstance(timestamp, (float, int)):
timestamp = datetime.fromtimestamp(timestamp)
timestamp = datetime.fromtimestamp(timestamp, timezone.utc)

with self._lock:
self._verify_and_update_metrics_state(step, metrics)
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_attribute.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from datetime import datetime
from unittest.mock import Mock

Expand Down Expand Up @@ -68,8 +69,9 @@ def test_tags(run, store):


def test_series(run, store):
run["my/series"].append(1, step=1, timestamp=10)
store.log.assert_called_with(metrics={"my/series": 1}, step=1, timestamp=10)
timestamp = time.time()
run["my/series"].append(1, step=1, timestamp=timestamp)
store.log.assert_called_with(metrics={"my/series": 1}, step=1, timestamp=timestamp)

run["my/series"].append({"foo": 1, "bar": 2}, step=2)
store.log.assert_called_with(metrics={"my/series/foo": 1, "my/series/bar": 2}, step=2, timestamp=None)
Expand Down

0 comments on commit 89c5302

Please sign in to comment.