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 bug where using some Pandas dtypes in the output of an ODFV fails #1994

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
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
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