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

Add materialize-incremental cli test #1445

Merged
merged 1 commit into from
Apr 8, 2021
Merged
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
63 changes: 44 additions & 19 deletions sdk/python/tests/test_e2e_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,48 @@
from pathlib import Path

import pandas as pd
from pytz import utc

import feast.driver_test_data as driver_data
from feast import FeatureStore
from tests.cli_utils import CliRunner, get_example_repo


def _get_last_feature_row(df: pd.DataFrame, driver_id):
""" Manually extract last feature value from a dataframe for a given driver_id """
filtered = df[df["driver_id"] == driver_id]
def _get_last_feature_row(df: pd.DataFrame, driver_id, max_date: datetime):
""" Manually extract last feature value from a dataframe for a given driver_id with up to `max_date` date """
filtered = df[
(df["driver_id"] == driver_id) & (df["datetime"] < max_date.replace(tzinfo=utc))
]
max_ts = filtered.loc[filtered["datetime"].idxmax()]["datetime"]
filtered_by_ts = filtered[filtered["datetime"] == max_ts]
return filtered_by_ts.loc[filtered_by_ts["created"].idxmax()]


def _assert_online_features(
store: FeatureStore, driver_df: pd.DataFrame, max_date: datetime
):
"""Assert that features in online store are up to date with `max_date` date."""
# Read features back
result = store.get_online_features(
feature_refs=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:avg_daily_trips",
],
entity_rows=[{"driver_id": 1001}],
)

assert "driver_hourly_stats__avg_daily_trips" in result.to_dict()

assert "driver_hourly_stats__conv_rate" in result.to_dict()
assert (
abs(
result.to_dict()["driver_hourly_stats__conv_rate"][0]
- _get_last_feature_row(driver_df, 1001, max_date)["conv_rate"]
)
< 0.01
)


def test_e2e_local() -> None:
"""
A more comprehensive than "basic" test, using local provider.
Expand Down Expand Up @@ -57,30 +86,26 @@ def test_e2e_local() -> None:
[
"materialize",
start_date.isoformat(),
end_date.isoformat(),
(end_date - timedelta(days=7)).isoformat(),
str(store.repo_path),
],
cwd=Path(store.repo_path),
)

assert r.returncode == 0

# Read features back
result = store.get_online_features(
feature_refs=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:avg_daily_trips",
_assert_online_features(store, driver_df, end_date - timedelta(days=7))

# feast materialize-incremental
r = runner.run(
[
"materialize-incremental",
end_date.isoformat(),
str(store.repo_path),
],
entity_rows=[{"driver_id": 1001}],
cwd=Path(store.repo_path),
)

assert "driver_hourly_stats__avg_daily_trips" in result.to_dict()
assert r.returncode == 0

assert "driver_hourly_stats__conv_rate" in result.to_dict()
assert (
abs(
result.to_dict()["driver_hourly_stats__conv_rate"][0]
- _get_last_feature_row(driver_df, 1001)["conv_rate"]
)
< 0.01
)
_assert_online_features(store, driver_df, end_date)