FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Fix STRING type handling in on-demand feature views by ntkathole · Pull Request #5669 · feast-dev/feast · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions sdk/python/feast/type_map.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

if this is invalid, shouldn't it raise?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

it's a negative test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Back | FazBrowse Home | New Git URL