Skip to content

featurebyte.ViewColumn.as_feature

as_feature(
feature_name: str,
offset: Union[str, NoneType]=None
) -> Feature

Description

Creates a lookup feature directly from the column in the View. For SCD views, lookup features are materialized through point-in-time joins, and the resulting value represents the active row for the natural key at the point-in-time indicated in the feature request.

To obtain a feature value at a specific time before the request's point-in-time, an offset can be specified.

Parameters

  • feature_name: str
    Name of the feature to create.

  • offset: Union[str, NoneType]
    When specified, retrieve feature value as of this offset prior to the point-in-time.

Returns

  • Feature

Raises

  • ValueError
    If the column is a temporary column not associated with any View

Examples

>>> customer_view = catalog.get_view("GROCERYCUSTOMER")
>>> # Extract operating system from BrowserUserAgent column
>>> customer_view["OperatingSystemIsWindows"] = customer_view.BrowserUserAgent.str.contains("Windows")
>>> # Create a feature from the OperatingSystemIsWindows column
>>> uses_windows = customer_view.OperatingSystemIsWindows.as_feature("UsesWindows")
If the view is a Slowly Changing Dimension View, you may also consider to create a feature that retrieves the entity's attribute at a point-in-time prior to the point-in-time specified in the feature request by specifying an offset.

>>> uses_windows_12w_ago = customer_view.OperatingSystemIsWindows.as_feature(
...   "UsesWindows_12w_ago", offset="12w"
... )