Skip to content

Commit

Permalink
Convert to using integral nanoseconds instead of datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
drake-nominal committed Oct 29, 2024
1 parent cac0bac commit adcab95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 13 additions & 6 deletions nominal/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
import urllib.parse
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from datetime import timedelta
from io import TextIOBase
from pathlib import Path
from types import MappingProxyType
Expand All @@ -31,21 +31,28 @@
from nominal.core._utils import HasRid, update_dataclass
from nominal.core.channel import Channel, _get_series_values_csv
from nominal.exceptions import NominalIngestError, NominalIngestFailed, NominalIngestMultiError
from nominal.ts import _MAX_TIMESTAMP, _MIN_TIMESTAMP, _AnyTimestampType, _SecondsNanos, _to_typed_timestamp_type
from nominal.ts import (
_MAX_TIMESTAMP,
_MIN_TIMESTAMP,
IntegralNanosecondsUTC,
_AnyTimestampType,
_SecondsNanos,
_to_typed_timestamp_type,
)

logger = logging.getLogger(__name__)


@dataclass(frozen=True)
class DatasetBounds:
start: datetime
end: datetime
start: IntegralNanosecondsUTC
end: IntegralNanosecondsUTC

@classmethod
def _from_conjure(cls, bounds: scout_catalog.Bounds) -> Self:
return cls(
start=_SecondsNanos.from_api(bounds.start).to_datetime(),
end=_SecondsNanos.from_api(bounds.end).to_datetime(),
start=_SecondsNanos.from_api(bounds.start).to_nanoseconds(),
end=_SecondsNanos.from_api(bounds.end).to_nanoseconds(),
)


Expand Down
7 changes: 2 additions & 5 deletions tests/core/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
from datetime import datetime, timedelta, timezone
from datetime import timedelta
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -30,10 +30,7 @@ def mock_dataset(mock_clients):
rid="test-rid",
name="Test Dataset",
description="A dataset for testing",
bounds=DatasetBounds(
start=datetime(year=2021, month=10, day=9, hour=10, minute=9, second=10, tzinfo=timezone.utc),
end=datetime(year=2021, month=10, day=9, hour=11, minute=9, second=10, tzinfo=timezone.utc),
),
bounds=DatasetBounds(start=123455, end=123456),
properties={},
labels=[],
_clients=mock_clients,
Expand Down

0 comments on commit adcab95

Please sign in to comment.