Skip to content

Commit

Permalink
Move _to_naive_utc to avoid circular import
Browse files Browse the repository at this point in the history
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
  • Loading branch information
judahrand committed Dec 20, 2021
1 parent aa6537e commit 3d8a471
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
9 changes: 0 additions & 9 deletions sdk/python/feast/infra/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from datetime import datetime
from pathlib import Path

import pytz

from feast.feature_view import FeatureView
from feast.infra.passthrough_provider import PassthroughProvider
from feast.protos.feast.core.Registry_pb2 import Registry as RegistryProto
Expand All @@ -24,13 +22,6 @@ def _table_id(project: str, table: FeatureView) -> str:
return f"{project}_{table.name}"


def _to_naive_utc(ts: datetime):
if ts.tzinfo is None:
return ts
else:
return ts.astimezone(pytz.utc).replace(tzinfo=None)


class LocalRegistryStore(RegistryStore):
def __init__(self, registry_config: RegistryConfig, repo_path: Path):
registry_path = Path(registry_config.path)
Expand Down
6 changes: 3 additions & 3 deletions sdk/python/feast/infra/offline_stores/offline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
FeastModuleImportError,
)
from feast.feature_view import FeatureView
from feast.infra.local import _to_naive_utc
from feast.infra.offline_stores.offline_store import OfflineStore
from feast.infra.provider import _get_requested_feature_views_to_features_dict
from feast.registry import Registry
from feast.utils import to_naive_utc

DEFAULT_ENTITY_DF_EVENT_TIMESTAMP_COL = "event_timestamp"

Expand Down Expand Up @@ -136,11 +136,11 @@ def get_feature_view_query_context(

min_event_timestamp = None
if feature_view.ttl:
min_event_timestamp = _to_naive_utc(
min_event_timestamp = to_naive_utc(
entity_df_timestamp_range[0] - feature_view.ttl
).isoformat()

max_event_timestamp = _to_naive_utc(entity_df_timestamp_range[1]).isoformat()
max_event_timestamp = to_naive_utc(entity_df_timestamp_range[1]).isoformat()

context = FeatureViewQueryContext(
name=feature_view.projection.name_to_use(),
Expand Down
13 changes: 3 additions & 10 deletions sdk/python/feast/infra/online_stores/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple

import pytz
from pydantic import StrictStr
from pydantic.schema import Literal

Expand All @@ -33,6 +32,7 @@
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
from feast.repo_config import FeastConfigBaseModel, RepoConfig
from feast.usage import log_exceptions_and_usage, tracing_span
from feast.utils import to_naive_utc


class SqliteOnlineStoreConfig(FeastConfigBaseModel):
Expand Down Expand Up @@ -95,9 +95,9 @@ def online_write_batch(
with conn:
for entity_key, values, timestamp, created_ts in data:
entity_key_bin = serialize_entity_key(entity_key)
timestamp = _to_naive_utc(timestamp)
timestamp = to_naive_utc(timestamp)
if created_ts is not None:
created_ts = _to_naive_utc(created_ts)
created_ts = to_naive_utc(created_ts)

for feature_name, val in values.items():
conn.execute(
Expand Down Expand Up @@ -222,13 +222,6 @@ def _table_id(project: str, table: FeatureView) -> str:
return f"{project}_{table.name}"


def _to_naive_utc(ts: datetime):
if ts.tzinfo is None:
return ts
else:
return ts.astimezone(pytz.utc).replace(tzinfo=None)


class SqliteTable(InfraObject):
"""
A Sqlite table managed by Feast.
Expand Down
7 changes: 7 additions & 0 deletions sdk/python/feast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ def make_tzaware(t: datetime) -> datetime:
return t.replace(tzinfo=utc)
else:
return t


def to_naive_utc(ts: datetime) -> datetime:
if ts.tzinfo is None:
return ts
else:
return ts.astimezone(utc).replace(tzinfo=None)

0 comments on commit 3d8a471

Please sign in to comment.