Skip to content

Commit b8daefa

Browse files
authored
Improve serialization performance (feast-dev#2165)
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
1 parent f279a7d commit b8daefa

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

sdk/python/feast/infra/provider.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,14 @@ def _convert_arrow_to_proto(
301301
feature_view: FeatureView,
302302
join_keys: List[str],
303303
) -> List[Tuple[EntityKeyProto, Dict[str, ValueProto], datetime, Optional[datetime]]]:
304+
# Avoid ChunkedArrays which guarentees `zero_copy_only` availiable.
305+
if isinstance(table, pyarrow.Table):
306+
table = table.to_batches()[0]
307+
304308
# Handle join keys
305-
join_key_values = {k: table.column(k).to_pylist() for k in join_keys}
309+
join_key_values = {
310+
k: table.column(k).to_numpy(zero_copy_only=False) for k in join_keys
311+
}
306312
entity_keys = [
307313
EntityKeyProto(
308314
join_keys=join_keys,
@@ -317,7 +323,7 @@ def _convert_arrow_to_proto(
317323
feature_dict = {
318324
feature.name: [
319325
python_value_to_proto_value(val, feature.dtype)
320-
for val in table.column(feature.name).to_pylist()
326+
for val in table.column(feature.name).to_numpy(zero_copy_only=False)
321327
]
322328
for feature in feature_view.features
323329
}
@@ -326,18 +332,22 @@ def _convert_arrow_to_proto(
326332
# Convert event_timestamps
327333
event_timestamps = [
328334
_coerce_datetime(val)
329-
for val in table.column(
330-
feature_view.batch_source.event_timestamp_column
331-
).to_pylist()
335+
for val in pandas.to_datetime(
336+
table.column(feature_view.batch_source.event_timestamp_column).to_numpy(
337+
zero_copy_only=False
338+
)
339+
)
332340
]
333341

334342
# Convert created_timestamps if they exist
335343
if feature_view.batch_source.created_timestamp_column:
336344
created_timestamps = [
337345
_coerce_datetime(val)
338-
for val in table.column(
339-
feature_view.batch_source.created_timestamp_column
340-
).to_pylist()
346+
for val in pandas.to_datetime(
347+
table.column(
348+
feature_view.batch_source.created_timestamp_column
349+
).to_numpy(zero_copy_only=False)
350+
)
341351
]
342352
else:
343353
created_timestamps = [None] * table.num_rows

sdk/python/feast/type_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _type_err(item, dtype):
207207
"double_list_val",
208208
[np.float64, np.float32, float],
209209
),
210-
ValueType.INT32_LIST: (Int32List, "int32_list_val", [np.int32, int]),
210+
ValueType.INT32_LIST: (Int32List, "int32_list_val", [np.int64, np.int32, int]),
211211
ValueType.INT64_LIST: (Int64List, "int64_list_val", [np.int64, np.int32, int]),
212212
ValueType.UNIX_TIMESTAMP_LIST: (
213213
Int64List,
@@ -234,7 +234,7 @@ def _type_err(item, dtype):
234234
ValueType.DOUBLE: ("double_val", lambda x: x, {float, np.float64}),
235235
ValueType.STRING: ("string_val", lambda x: str(x), None),
236236
ValueType.BYTES: ("bytes_val", lambda x: x, {bytes}),
237-
ValueType.BOOL: ("bool_val", lambda x: x, {bool}),
237+
ValueType.BOOL: ("bool_val", lambda x: x, {bool, np.bool_}),
238238
}
239239

240240

0 commit comments

Comments
 (0)