Skip to content

Commit 4d0b50f

Browse files
authored
Fix bug where using some Pandas dtypes in the output of an ODFV fails (feast-dev#1994)
* Add test for feature using Pandas nullable dtype Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com> * Lower case Python type names to maximize match Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
1 parent 38cf9cb commit 4d0b50f

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

sdk/python/feast/type_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def python_type_to_feast_value_type(
114114
Returns:
115115
Feast Value Type
116116
"""
117-
type_name = type_name or type(value).__name__
117+
type_name = (type_name or type(value).__name__).lower()
118118

119119
type_map = {
120120
"int": ValueType.INT64,
@@ -131,7 +131,7 @@ def python_type_to_feast_value_type(
131131
"int8": ValueType.INT32,
132132
"bool": ValueType.BOOL,
133133
"timedelta": ValueType.UNIX_TIMESTAMP,
134-
"Timestamp": ValueType.UNIX_TIMESTAMP,
134+
"timestamp": ValueType.UNIX_TIMESTAMP,
135135
"datetime": ValueType.UNIX_TIMESTAMP,
136136
"datetime64[ns]": ValueType.UNIX_TIMESTAMP,
137137
"datetime64[ns, tz]": ValueType.UNIX_TIMESTAMP,

sdk/python/tests/integration/feature_repos/universal/feature_views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def conv_rate_plus_100(features_df: pd.DataFrame) -> pd.DataFrame:
4444
df["conv_rate_plus_val_to_add"] = (
4545
features_df["conv_rate"] + features_df["val_to_add"]
4646
)
47+
df["conv_rate_plus_100_rounded"] = (
48+
df["conv_rate_plus_100"].astype("float").round().astype(pd.Int32Dtype())
49+
)
4750
return df
4851

4952

@@ -55,6 +58,7 @@ def conv_rate_plus_100_feature_view(
5558
_features = features or [
5659
Feature("conv_rate_plus_100", ValueType.DOUBLE),
5760
Feature("conv_rate_plus_val_to_add", ValueType.DOUBLE),
61+
Feature("conv_rate_plus_100_rounded", ValueType.INT32),
5862
]
5963
return OnDemandFeatureView(
6064
name=conv_rate_plus_100.__name__,

sdk/python/tests/integration/offline_store/test_universal_historical_retrieval.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ def get_expected_training_df(
228228

229229
conv_feature_name = "driver_stats__conv_rate" if full_feature_names else "conv_rate"
230230
expected_df["conv_rate_plus_100"] = expected_df[conv_feature_name] + 100
231+
expected_df["conv_rate_plus_100_rounded"] = (
232+
expected_df["conv_rate_plus_100"]
233+
.astype("float")
234+
.round()
235+
.astype(pd.Int32Dtype())
236+
)
231237
expected_df["conv_rate_plus_val_to_add"] = (
232238
expected_df[conv_feature_name] + expected_df["val_to_add"]
233239
)
@@ -375,6 +381,7 @@ def test_historical_features(environment, universal_data_sources, full_feature_n
375381
expected_df_query = expected_df.drop(
376382
columns=[
377383
"conv_rate_plus_100",
384+
"conv_rate_plus_100_rounded",
378385
"val_to_add",
379386
"conv_rate_plus_val_to_add",
380387
"driver_age",
@@ -426,6 +433,7 @@ def test_historical_features(environment, universal_data_sources, full_feature_n
426433
"customer_profile:avg_passenger_count",
427434
"customer_profile:lifetime_trip_count",
428435
"conv_rate_plus_100:conv_rate_plus_100",
436+
"conv_rate_plus_100:conv_rate_plus_100_rounded",
429437
"conv_rate_plus_100:conv_rate_plus_val_to_add",
430438
"order:order_is_success",
431439
"global_stats:num_rides",

sdk/python/tests/integration/registration/test_universal_odfv_feature_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_infer_odfv_features(environment, universal_data_sources, infer_features
3030
feast_objects = [driver_hourly_stats, driver_odfv, driver(), customer()]
3131
store.apply(feast_objects)
3232
odfv = store.get_on_demand_feature_view("conv_rate_plus_100")
33-
assert len(odfv.features) == 2
33+
assert len(odfv.features) == 3
3434

3535

3636
@pytest.mark.integration

0 commit comments

Comments
 (0)