Skip to content
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
10 changes: 10 additions & 0 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ def python_type_to_feast_value_type(
if type_name in type_map:
return type_map[type_name]

# Handle pandas "object" dtype by inspecting the actual value
if type_name == "object" and value is not None:
# Check the actual type of the value
actual_type = type(value).__name__.lower()
if actual_type == "str":
return ValueType.STRING
# If it's a different type wrapped in object, try to infer from the value
elif actual_type in type_map:
return type_map[actual_type]

if isinstance(value, np.ndarray) and str(value.dtype) in type_map:
item_type = type_map[str(value.dtype)]
return ValueType[item_type.name + "_LIST"]
Expand Down
25 changes: 11 additions & 14 deletions sdk/python/tests/unit/infra/test_inference_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,27 @@ def python_native_test_view(input_dict: dict[str, Any]) -> dict[str, Any]:

python_native_test_view.infer_features()


def test_on_demand_features_invalid_type_inference():
# Create Feature Views
date_request = RequestSource(
name="date_request",
schema=[Field(name="some_date", dtype=UnixTimestamp)],
)

@on_demand_feature_view(
sources=[date_request],
schema=[
Field(name="output", dtype=UnixTimestamp),
Field(name="object_output", dtype=String),
],
)
def invalid_test_view(features_df: pd.DataFrame) -> pd.DataFrame:
def object_string_test_view(features_df: pd.DataFrame) -> pd.DataFrame:
data = pd.DataFrame()
data["output"] = features_df["some_date"]
data["object_output"] = features_df["some_date"].astype(str)
return data

with pytest.raises(ValueError, match="Value with native type object"):
invalid_test_view.infer_features()
object_string_test_view.infer_features()


def test_on_demand_features_invalid_type_inference():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is invalid, shouldn't it raise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a negative test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is with pytest.raises() sections which catch exceptions raised when mode is mismatched or feature is missing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh nice i see on line 138, thank you.

date_request = RequestSource(
name="date_request",
schema=[Field(name="some_date", dtype=UnixTimestamp)],
)

@on_demand_feature_view(
schema=[
Expand Down Expand Up @@ -184,14 +182,13 @@ def test_view(features_df: pd.DataFrame) -> pd.DataFrame:
Field(name="object_output", dtype=String),
],
)
def invalid_test_view(features_df: pd.DataFrame) -> pd.DataFrame:
def object_string_view(features_df: pd.DataFrame) -> pd.DataFrame:
data = pd.DataFrame()
data["output"] = features_df["some_date"]
data["object_output"] = features_df["some_date"].astype(str)
return data

with pytest.raises(ValueError, match="Value with native type object"):
invalid_test_view.infer_features()
object_string_view.infer_features()

@on_demand_feature_view(
sources=[date_request],
Expand Down
Loading