Skip to content
Prev Previous commit
Next Next commit
Fix
Signed-off-by: Kevin Zhang <kzhang@tecton.ai>
  • Loading branch information
kevjumba committed Apr 21, 2022
commit 390772c65aa954e54d6be6271e9dff53152c6ee9
1 change: 0 additions & 1 deletion sdk/python/feast/on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def on_demand_feature_view(
),
DeprecationWarning,
)

_sources = sources or []
if inputs and sources:
raise ValueError("At most one of `sources` or `inputs` can be specified.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_infer_odfv_features(environment, universal_data_sources, infer_features
)
request_source = create_conv_rate_request_source()
driver_odfv = conv_rate_plus_100_feature_view(
{"driver": driver_hourly_stats, "input_request": request_source},
[driver_hourly_stats, request_source],
infer_features=infer_features,
)

Expand Down Expand Up @@ -85,7 +85,7 @@ def test_infer_odfv_features_with_error(environment, universal_data_sources):
)
request_source = create_conv_rate_request_source()
driver_odfv = conv_rate_plus_100_feature_view(
{"driver": driver_hourly_stats, "input_request": request_source},
[driver_hourly_stats, request_source],
features=features,
)

Expand Down
62 changes: 60 additions & 2 deletions sdk/python/tests/unit/test_on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from datetime import date
import pandas as pd

import pytest
from feast.feature_view import FeatureView
from feast.field import Field
from feast.infra.offline_stores.file_source import FileSource
from feast.on_demand_feature_view import OnDemandFeatureView
from feast import RequestSource
from feast.types import String, UnixTimestamp
from feast.on_demand_feature_view import OnDemandFeatureView, on_demand_feature_view
from feast.types import Float32


Expand Down Expand Up @@ -100,3 +103,58 @@ def test_hash():
on_demand_feature_view_4,
}
assert len(s4) == 3

def test_inputs_parameter_deprecation_in_odfv():
date_request = RequestSource(
name="date_request", schema=[Field(name="some_date", dtype=UnixTimestamp)],
)
with pytest.warns(DeprecationWarning):
@on_demand_feature_view(
inputs={"date_request": date_request},
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.

oh hah never mind, you have this test. Love it.

schema=[
Field(name="output", dtype=UnixTimestamp),
Field(name="string_output", dtype=String),
],
)
def test_view(features_df: pd.DataFrame) -> pd.DataFrame:
data = pd.DataFrame()
data["output"] = features_df["some_date"]
data["string_output"] = features_df["some_date"].astype(pd.StringDtype())
return data
odfv = test_view
assert odfv.name == "test_view"
assert len(odfv.source_request_sources) == 1
assert odfv.source_request_sources["date_request"].name == "date_request"
assert odfv.source_request_sources["date_request"].schema == date_request.schema

with pytest.raises(ValueError):
@on_demand_feature_view(
inputs={"date_request": date_request},
sources=[date_request],
schema=[
Field(name="output", dtype=UnixTimestamp),
Field(name="string_output", dtype=String),
],
)
def incorrect_testview(features_df: pd.DataFrame) -> pd.DataFrame:
data = pd.DataFrame()
data["output"] = features_df["some_date"]
data["string_output"] = features_df["some_date"].astype(pd.StringDtype())
return data


@on_demand_feature_view(
inputs={"odfv": date_request},
schema=[
Field(name="output", dtype=UnixTimestamp),
Field(name="string_output", dtype=String),
],
)
def test_correct_view(features_df: pd.DataFrame) -> pd.DataFrame:
data = pd.DataFrame()
data["output"] = features_df["some_date"]
data["string_output"] = features_df["some_date"].astype(pd.StringDtype())
return data
odfv = test_correct_view
assert odfv.name == "test_correct_view"
assert odfv.source_request_sources["date_request"].schema == date_request.schema