Skip to content

Commit

Permalink
Clean up docstring tests (#1778)
Browse files Browse the repository at this point in the history
* Clean up docstring tests

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

* Lint

Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 authored Aug 16, 2021
1 parent 351b913 commit 74c7bed
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 91 deletions.
97 changes: 6 additions & 91 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,29 +411,9 @@ def get_historical_features(
Examples:
Retrieve historical features from a local offline store.
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
>>> from datetime import timedelta
>>> from feast import FeatureStore, RepoConfig
>>> import pandas as pd
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
>>> # Before retrieving historical features, we must register the appropriate entity and featureview.
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id")
>>> driver_hourly_stats = FileSource(
... path="feature_repo/data/driver_stats.parquet",
... event_timestamp_column="event_timestamp",
... created_timestamp_column="created",
... )
>>> driver_hourly_stats_view = FeatureView(
... name="driver_hourly_stats",
... entities=["driver_id"],
... ttl=timedelta(seconds=86400 * 1),
... features=[
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
... ],
... batch_source=driver_hourly_stats,
... )
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
>>> entity_df = pd.DataFrame.from_dict(
... {
... "driver_id": [1001, 1002],
Expand Down Expand Up @@ -516,28 +496,9 @@ def materialize_incremental(
Examples:
Materialize all features into the online store up to 5 minutes ago.
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
>>> from datetime import timedelta
>>> from feast import FeatureStore, RepoConfig
>>> from datetime import datetime, timedelta
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
>>> # Before materializing, we must register the appropriate entity and featureview.
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
>>> driver_hourly_stats = FileSource(
... path="feature_repo/data/driver_stats.parquet",
... event_timestamp_column="event_timestamp",
... created_timestamp_column="created",
... )
>>> driver_hourly_stats_view = FeatureView(
... name="driver_hourly_stats",
... entities=["driver_id"],
... ttl=timedelta(seconds=86400 * 1),
... features=[
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
... ],
... batch_source=driver_hourly_stats,
... )
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
>>> fs.materialize_incremental(end_date=datetime.utcnow() - timedelta(minutes=5))
Materializing...
<BLANKLINE>
Expand Down Expand Up @@ -620,28 +581,9 @@ def materialize(
Materialize all features into the online store over the interval
from 3 hours ago to 10 minutes ago.
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
>>> from datetime import timedelta
>>> from feast import FeatureStore, RepoConfig
>>> from datetime import datetime, timedelta
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
>>> # Before materializing, we must register the appropriate entity and featureview.
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
>>> driver_hourly_stats = FileSource(
... path="feature_repo/data/driver_stats.parquet",
... event_timestamp_column="event_timestamp",
... created_timestamp_column="created",
... )
>>> driver_hourly_stats_view = FeatureView(
... name="driver_hourly_stats",
... entities=["driver_id"],
... ttl=timedelta(seconds=86400 * 1),
... features=[
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
... ],
... batch_source=driver_hourly_stats,
... )
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
>>> fs.materialize(
... start_date=datetime.utcnow() - timedelta(hours=3), end_date=datetime.utcnow() - timedelta(minutes=10)
... )
Expand Down Expand Up @@ -732,35 +674,8 @@ def get_online_features(
Materialize all features into the online store over the interval
from 3 hours ago to 10 minutes ago, and then retrieve these online features.
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
>>> from datetime import timedelta
>>> import pandas as pd
>>> from feast import FeatureStore, RepoConfig
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
>>> # Before getting online features, we must register the appropriate entity and featureview and then materialize the features.
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
>>> driver_hourly_stats = FileSource(
... path="feature_repo/data/driver_stats.parquet",
... event_timestamp_column="event_timestamp",
... created_timestamp_column="created",
... )
>>> driver_hourly_stats_view = FeatureView(
... name="driver_hourly_stats",
... entities=["driver_id"],
... ttl=timedelta(seconds=86400 * 1),
... features=[
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
... ],
... batch_source=driver_hourly_stats,
... )
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
>>> fs.materialize(
... start_date=datetime.utcnow() - timedelta(hours=3), end_date=datetime.utcnow() - timedelta(minutes=10)
... )
Materializing...
<BLANKLINE>
...
>>> online_response = fs.get_online_features(
... features=[
... "driver_hourly_stats:conv_rate",
Expand Down
42 changes: 42 additions & 0 deletions sdk/python/tests/doctest/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,51 @@

def setup_feature_store(docstring_tests):
"""Prepares the local environment for a FeatureStore docstring test."""
from datetime import datetime, timedelta

from feast import (
Entity,
Feature,
FeatureStore,
FeatureView,
FileSource,
RepoConfig,
ValueType,
)
from feast.repo_operations import init_repo

init_repo("feature_repo", "local")
fs = FeatureStore(
config=RepoConfig(
registry="feature_repo/data/registry.db",
project="feature_repo",
provider="local",
)
)
driver = Entity(
name="driver_id", value_type=ValueType.INT64, description="driver id",
)
driver_hourly_stats = FileSource(
path="feature_repo/data/driver_stats.parquet",
event_timestamp_column="event_timestamp",
created_timestamp_column="created",
)
driver_hourly_stats_view = FeatureView(
name="driver_hourly_stats",
entities=["driver_id"],
ttl=timedelta(seconds=86400 * 1),
features=[
Feature(name="conv_rate", dtype=ValueType.FLOAT),
Feature(name="acc_rate", dtype=ValueType.FLOAT),
Feature(name="avg_daily_trips", dtype=ValueType.INT64),
],
batch_source=driver_hourly_stats,
)
fs.apply([driver_hourly_stats_view, driver])
fs.materialize(
start_date=datetime.utcnow() - timedelta(hours=3),
end_date=datetime.utcnow() - timedelta(minutes=10),
)


def teardown_feature_store(docstring_tests):
Expand Down

0 comments on commit 74c7bed

Please sign in to comment.