Skip to content

Commit 74c7bed

Browse files
Clean up docstring tests (feast-dev#1778)
* Clean up docstring tests Signed-off-by: Felix Wang <[email protected]> * Lint Signed-off-by: Felix Wang <[email protected]>
1 parent 351b913 commit 74c7bed

File tree

2 files changed

+48
-91
lines changed

2 files changed

+48
-91
lines changed

sdk/python/feast/feature_store.py

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -411,29 +411,9 @@ def get_historical_features(
411411
Examples:
412412
Retrieve historical features from a local offline store.
413413
414-
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
415-
>>> from datetime import timedelta
414+
>>> from feast import FeatureStore, RepoConfig
416415
>>> import pandas as pd
417416
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
418-
>>> # Before retrieving historical features, we must register the appropriate entity and featureview.
419-
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id")
420-
>>> driver_hourly_stats = FileSource(
421-
... path="feature_repo/data/driver_stats.parquet",
422-
... event_timestamp_column="event_timestamp",
423-
... created_timestamp_column="created",
424-
... )
425-
>>> driver_hourly_stats_view = FeatureView(
426-
... name="driver_hourly_stats",
427-
... entities=["driver_id"],
428-
... ttl=timedelta(seconds=86400 * 1),
429-
... features=[
430-
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
431-
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
432-
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
433-
... ],
434-
... batch_source=driver_hourly_stats,
435-
... )
436-
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
437417
>>> entity_df = pd.DataFrame.from_dict(
438418
... {
439419
... "driver_id": [1001, 1002],
@@ -516,28 +496,9 @@ def materialize_incremental(
516496
Examples:
517497
Materialize all features into the online store up to 5 minutes ago.
518498
519-
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
520-
>>> from datetime import timedelta
499+
>>> from feast import FeatureStore, RepoConfig
500+
>>> from datetime import datetime, timedelta
521501
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
522-
>>> # Before materializing, we must register the appropriate entity and featureview.
523-
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
524-
>>> driver_hourly_stats = FileSource(
525-
... path="feature_repo/data/driver_stats.parquet",
526-
... event_timestamp_column="event_timestamp",
527-
... created_timestamp_column="created",
528-
... )
529-
>>> driver_hourly_stats_view = FeatureView(
530-
... name="driver_hourly_stats",
531-
... entities=["driver_id"],
532-
... ttl=timedelta(seconds=86400 * 1),
533-
... features=[
534-
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
535-
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
536-
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
537-
... ],
538-
... batch_source=driver_hourly_stats,
539-
... )
540-
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
541502
>>> fs.materialize_incremental(end_date=datetime.utcnow() - timedelta(minutes=5))
542503
Materializing...
543504
<BLANKLINE>
@@ -620,28 +581,9 @@ def materialize(
620581
Materialize all features into the online store over the interval
621582
from 3 hours ago to 10 minutes ago.
622583
623-
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
624-
>>> from datetime import timedelta
584+
>>> from feast import FeatureStore, RepoConfig
585+
>>> from datetime import datetime, timedelta
625586
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
626-
>>> # Before materializing, we must register the appropriate entity and featureview.
627-
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
628-
>>> driver_hourly_stats = FileSource(
629-
... path="feature_repo/data/driver_stats.parquet",
630-
... event_timestamp_column="event_timestamp",
631-
... created_timestamp_column="created",
632-
... )
633-
>>> driver_hourly_stats_view = FeatureView(
634-
... name="driver_hourly_stats",
635-
... entities=["driver_id"],
636-
... ttl=timedelta(seconds=86400 * 1),
637-
... features=[
638-
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
639-
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
640-
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
641-
... ],
642-
... batch_source=driver_hourly_stats,
643-
... )
644-
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
645587
>>> fs.materialize(
646588
... start_date=datetime.utcnow() - timedelta(hours=3), end_date=datetime.utcnow() - timedelta(minutes=10)
647589
... )
@@ -732,35 +674,8 @@ def get_online_features(
732674
Materialize all features into the online store over the interval
733675
from 3 hours ago to 10 minutes ago, and then retrieve these online features.
734676
735-
>>> from feast import FeatureStore, Entity, FeatureView, Feature, ValueType, FileSource, RepoConfig
736-
>>> from datetime import timedelta
737-
>>> import pandas as pd
677+
>>> from feast import FeatureStore, RepoConfig
738678
>>> fs = FeatureStore(config=RepoConfig(registry="feature_repo/data/registry.db", project="feature_repo", provider="local"))
739-
>>> # Before getting online features, we must register the appropriate entity and featureview and then materialize the features.
740-
>>> driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",)
741-
>>> driver_hourly_stats = FileSource(
742-
... path="feature_repo/data/driver_stats.parquet",
743-
... event_timestamp_column="event_timestamp",
744-
... created_timestamp_column="created",
745-
... )
746-
>>> driver_hourly_stats_view = FeatureView(
747-
... name="driver_hourly_stats",
748-
... entities=["driver_id"],
749-
... ttl=timedelta(seconds=86400 * 1),
750-
... features=[
751-
... Feature(name="conv_rate", dtype=ValueType.FLOAT),
752-
... Feature(name="acc_rate", dtype=ValueType.FLOAT),
753-
... Feature(name="avg_daily_trips", dtype=ValueType.INT64),
754-
... ],
755-
... batch_source=driver_hourly_stats,
756-
... )
757-
>>> fs.apply([driver_hourly_stats_view, driver]) # register entity and feature view
758-
>>> fs.materialize(
759-
... start_date=datetime.utcnow() - timedelta(hours=3), end_date=datetime.utcnow() - timedelta(minutes=10)
760-
... )
761-
Materializing...
762-
<BLANKLINE>
763-
...
764679
>>> online_response = fs.get_online_features(
765680
... features=[
766681
... "driver_hourly_stats:conv_rate",

sdk/python/tests/doctest/test_all.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,51 @@
99

1010
def setup_feature_store(docstring_tests):
1111
"""Prepares the local environment for a FeatureStore docstring test."""
12+
from datetime import datetime, timedelta
13+
14+
from feast import (
15+
Entity,
16+
Feature,
17+
FeatureStore,
18+
FeatureView,
19+
FileSource,
20+
RepoConfig,
21+
ValueType,
22+
)
1223
from feast.repo_operations import init_repo
1324

1425
init_repo("feature_repo", "local")
26+
fs = FeatureStore(
27+
config=RepoConfig(
28+
registry="feature_repo/data/registry.db",
29+
project="feature_repo",
30+
provider="local",
31+
)
32+
)
33+
driver = Entity(
34+
name="driver_id", value_type=ValueType.INT64, description="driver id",
35+
)
36+
driver_hourly_stats = FileSource(
37+
path="feature_repo/data/driver_stats.parquet",
38+
event_timestamp_column="event_timestamp",
39+
created_timestamp_column="created",
40+
)
41+
driver_hourly_stats_view = FeatureView(
42+
name="driver_hourly_stats",
43+
entities=["driver_id"],
44+
ttl=timedelta(seconds=86400 * 1),
45+
features=[
46+
Feature(name="conv_rate", dtype=ValueType.FLOAT),
47+
Feature(name="acc_rate", dtype=ValueType.FLOAT),
48+
Feature(name="avg_daily_trips", dtype=ValueType.INT64),
49+
],
50+
batch_source=driver_hourly_stats,
51+
)
52+
fs.apply([driver_hourly_stats_view, driver])
53+
fs.materialize(
54+
start_date=datetime.utcnow() - timedelta(hours=3),
55+
end_date=datetime.utcnow() - timedelta(minutes=10),
56+
)
1557

1658

1759
def teardown_feature_store(docstring_tests):

0 commit comments

Comments
 (0)