Skip to content

Commit 9f9f83d

Browse files
author
Tsotne Tabidze
authored
Fix time zone access with native python datetimes (feast-dev#1469)
Signed-off-by: Tsotne Tabidze <[email protected]>
1 parent 3d0abf2 commit 9f9f83d

File tree

1 file changed

+9
-5
lines changed
  • sdk/python/feast/infra/offline_stores

1 file changed

+9
-5
lines changed

sdk/python/feast/infra/offline_stores/file.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def evaluate_historical_retrieval():
5959
# Make sure all event timestamp fields are tz-aware. We default tz-naive fields to UTC
6060
entity_df[ENTITY_DF_EVENT_TIMESTAMP_COL] = entity_df[
6161
ENTITY_DF_EVENT_TIMESTAMP_COL
62-
].apply(lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc))
62+
].apply(lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc))
6363
# Sort entity dataframe prior to join, and create a copy to prevent modifying the original
6464
entity_df_with_features = entity_df.sort_values(
6565
ENTITY_DF_EVENT_TIMESTAMP_COL
@@ -83,12 +83,16 @@ def evaluate_historical_retrieval():
8383
# Make sure all timestamp fields are tz-aware. We default tz-naive fields to UTC
8484
df_to_join[event_timestamp_column] = df_to_join[
8585
event_timestamp_column
86-
].apply(lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc))
86+
].apply(
87+
lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc)
88+
)
8789
if created_timestamp_column:
8890
df_to_join[created_timestamp_column] = df_to_join[
8991
created_timestamp_column
9092
].apply(
91-
lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc)
93+
lambda x: x
94+
if x.tzinfo is not None
95+
else x.replace(tzinfo=pytz.utc)
9296
)
9397

9498
# Sort dataframe by the event timestamp column
@@ -181,12 +185,12 @@ def pull_latest_from_table_or_query(
181185
source_df = pd.read_parquet(data_source.path)
182186
# Make sure all timestamp fields are tz-aware. We default tz-naive fields to UTC
183187
source_df[event_timestamp_column] = source_df[event_timestamp_column].apply(
184-
lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc)
188+
lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc)
185189
)
186190
if created_timestamp_column:
187191
source_df[created_timestamp_column] = source_df[
188192
created_timestamp_column
189-
].apply(lambda x: x if x.tz is not None else x.replace(tzinfo=pytz.utc))
193+
].apply(lambda x: x if x.tzinfo is not None else x.replace(tzinfo=pytz.utc))
190194

191195
ts_columns = (
192196
[event_timestamp_column, created_timestamp_column]

0 commit comments

Comments
 (0)