Skip to content

Commit

Permalink
Fix bug where using some Pandas dtypes in the output of an ODFV fails (
Browse files Browse the repository at this point in the history
…#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>
  • Loading branch information
judahrand committed Nov 5, 2021
1 parent 38cf9cb commit 4d0b50f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def python_type_to_feast_value_type(
Returns:
Feast Value Type
"""
type_name = type_name or type(value).__name__
type_name = (type_name or type(value).__name__).lower()

type_map = {
"int": ValueType.INT64,
Expand All @@ -131,7 +131,7 @@ def python_type_to_feast_value_type(
"int8": ValueType.INT32,
"bool": ValueType.BOOL,
"timedelta": ValueType.UNIX_TIMESTAMP,
"Timestamp": ValueType.UNIX_TIMESTAMP,
"timestamp": ValueType.UNIX_TIMESTAMP,
"datetime": ValueType.UNIX_TIMESTAMP,
"datetime64[ns]": ValueType.UNIX_TIMESTAMP,
"datetime64[ns, tz]": ValueType.UNIX_TIMESTAMP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def conv_rate_plus_100(features_df: pd.DataFrame) -> pd.DataFrame:
df["conv_rate_plus_val_to_add"] = (
features_df["conv_rate"] + features_df["val_to_add"]
)
df["conv_rate_plus_100_rounded"] = (
df["conv_rate_plus_100"].astype("float").round().astype(pd.Int32Dtype())
)
return df


Expand All @@ -55,6 +58,7 @@ def conv_rate_plus_100_feature_view(
_features = features or [
Feature("conv_rate_plus_100", ValueType.DOUBLE),
Feature("conv_rate_plus_val_to_add", ValueType.DOUBLE),
Feature("conv_rate_plus_100_rounded", ValueType.INT32),
]
return OnDemandFeatureView(
name=conv_rate_plus_100.__name__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ def get_expected_training_df(

conv_feature_name = "driver_stats__conv_rate" if full_feature_names else "conv_rate"
expected_df["conv_rate_plus_100"] = expected_df[conv_feature_name] + 100
expected_df["conv_rate_plus_100_rounded"] = (
expected_df["conv_rate_plus_100"]
.astype("float")
.round()
.astype(pd.Int32Dtype())
)
expected_df["conv_rate_plus_val_to_add"] = (
expected_df[conv_feature_name] + expected_df["val_to_add"]
)
Expand Down Expand Up @@ -375,6 +381,7 @@ def test_historical_features(environment, universal_data_sources, full_feature_n
expected_df_query = expected_df.drop(
columns=[
"conv_rate_plus_100",
"conv_rate_plus_100_rounded",
"val_to_add",
"conv_rate_plus_val_to_add",
"driver_age",
Expand Down Expand Up @@ -426,6 +433,7 @@ def test_historical_features(environment, universal_data_sources, full_feature_n
"customer_profile:avg_passenger_count",
"customer_profile:lifetime_trip_count",
"conv_rate_plus_100:conv_rate_plus_100",
"conv_rate_plus_100:conv_rate_plus_100_rounded",
"conv_rate_plus_100:conv_rate_plus_val_to_add",
"order:order_is_success",
"global_stats:num_rides",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_infer_odfv_features(environment, universal_data_sources, infer_features
feast_objects = [driver_hourly_stats, driver_odfv, driver(), customer()]
store.apply(feast_objects)
odfv = store.get_on_demand_feature_view("conv_rate_plus_100")
assert len(odfv.features) == 2
assert len(odfv.features) == 3


@pytest.mark.integration
Expand Down

0 comments on commit 4d0b50f

Please sign in to comment.