Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time zone access with native python datetimes #1469

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions sdk/python/feast/infra/offline_stores/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def evaluate_historical_retrieval():
# Make sure all event timestamp fields are tz-aware. We default tz-naive fields to UTC
entity_df[ENTITY_DF_EVENT_TIMESTAMP_COL] = entity_df[
ENTITY_DF_EVENT_TIMESTAMP_COL
].apply(lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc))
].apply(lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc))
# Sort entity dataframe prior to join, and create a copy to prevent modifying the original
entity_df_with_features = entity_df.sort_values(
ENTITY_DF_EVENT_TIMESTAMP_COL
Expand All @@ -83,12 +83,16 @@ def evaluate_historical_retrieval():
# Make sure all timestamp fields are tz-aware. We default tz-naive fields to UTC
df_to_join[event_timestamp_column] = df_to_join[
event_timestamp_column
].apply(lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc))
].apply(
lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc)
)
if created_timestamp_column:
df_to_join[created_timestamp_column] = df_to_join[
created_timestamp_column
].apply(
lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc)
lambda x: x
if x.tzinfo is not None
else x.replace(tzinfo=pytz.utc)
)

# Sort dataframe by the event timestamp column
Expand Down Expand Up @@ -181,12 +185,12 @@ def pull_latest_from_table_or_query(
source_df = pd.read_parquet(data_source.path)
# Make sure all timestamp fields are tz-aware. We default tz-naive fields to UTC
source_df[event_timestamp_column] = source_df[event_timestamp_column].apply(
lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc)
lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc)
)
if created_timestamp_column:
source_df[created_timestamp_column] = source_df[
created_timestamp_column
].apply(lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc))
].apply(lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc))

ts_columns = (
[event_timestamp_column, created_timestamp_column]
Expand Down