Skip to content

Commit 0f5bd69

Browse files
authored
Replace batch with historical for Python SDK retrieval (#842)
* Create get_historical_features method * Update references from get_batch_features to get_historical_features * Fix missing names and comments
1 parent b47d89d commit 0f5bd69

8 files changed

Lines changed: 47 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fs = feast.Client('feast.example.com')
3232
customer_features = ['CreditScore', 'Balance', 'Age', 'NumOfProducts', 'IsActive']
3333
3434
# Training your model (typically from a notebook or pipeline)
35-
data = fs.get_batch_features(customer_features, customer_entities)
35+
data = fs.get_historical_features(customer_features, customer_entities)
3636
my_model = ml.fit(data)
3737
3838
# Serving predictions (when serving the model in production)

‎docs/user-guide/feature-retrieval.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ features = self._features + [self._target]
4848
# Retrieve training dataset from Feast. The "entity_df" is a dataframe that contains
4949
# timestamps and entity keys. In this case, it is a dataframe with two columns.
5050
# One timestamp column, and one customer id column
51-
dataset = client.get_batch_features(
51+
dataset = client.get_historical_features(
5252
feature_refs=features,
5353
entity_rows=entity_df
5454
)
@@ -59,7 +59,7 @@ df = dataset.to_dataframe()
5959
```
6060

6161
{% hint style="info" %}
62-
When no project is specified when retrieving features with `get_batch_features()`, Feast infers that the features specified belong to the `default` project. To retrieve from another project, specify the `default` parameter when retrieving features.
62+
When no project is specified when retrieving features with `get_historical_features()`, Feast infers that the features specified belong to the `default` project. To retrieve from another project, specify the `default` parameter when retrieving features.
6363
{% endhint %}
6464

6565
In the above example, Feast does a point in time correct query from a single feature set. For each timestamp and entity key combination that is provided by `entity_df`, Feast determines the values of all the features in the `features` list at that respective point in time and then joins features values to that specific entity value and timestamp, and repeats this process for all timestamps.
@@ -88,7 +88,7 @@ features = [
8888
]
8989

9090

91-
dataset = client.get_batch_features(
91+
dataset = client.get_historical_features(
9292
feature_refs=features, # this is a list of feature references
9393
entity_rows=entity_df # This is the entity dataframe above
9494
)
@@ -111,10 +111,10 @@ Point-in-time-correct joins also prevents the occurrence of feature leakage by t
111111

112112
Feast is able to compute [TFDV](https://tensorflow.google.cn/tfx/tutorials/data_validation/tfdv_basic) compatible statistics over data retrieved from historical stores. The statistics can be used in conjunction with feature schemas and TFDV to verify the integrity of your retrieved dataset, or to [Facets](https://github.com/PAIR-code/facets) to visualize the distribution.
113113

114-
The computation of statistics is not enabled by default. To indicate to Feast that the statistics are to be computed for a given historical retrieval request, pass `compute_statistics=True` to `get_batch_features`.
114+
The computation of statistics is not enabled by default. To indicate to Feast that the statistics are to be computed for a given historical retrieval request, pass `compute_statistics=True` to `get_historical_features`.
115115

116116
```python
117-
dataset = client.get_batch_features(
117+
dataset = client.get_historical_features(
118118
feature_refs=features,
119119
entity_rows=entity_df
120120
compute_statistics=True

‎examples/basic/basic.ipynb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@
572572
"cell_type": "markdown",
573573
"metadata": {},
574574
"source": [
575-
"By calling the `get_batch_features` method we are able to retrieve a `job` object. This object can be used to retrieve the resulting training dataset that is exported by Feast. \n",
575+
"By calling the `get_historical_features` method we are able to retrieve a `job` object. This object can be used to retrieve the resulting training dataset that is exported by Feast. \n",
576576
"\n",
577577
"The dataset that is returned will contain feature values for each entity and timestamp combination in `entity_rows`."
578578
]
@@ -585,7 +585,7 @@
585585
},
586586
"outputs": [],
587587
"source": [
588-
"job = batch_client.get_batch_features(\n",
588+
"job = batch_client.get_historical_features(\n",
589589
" feature_refs=[\n",
590590
" f\"daily_transactions\", \n",
591591
" f\"total_transactions\", \n",

‎examples/feast-xgboost-churn-prediction-tutorial/Telecom Customer Churn Prediction (with Feast and XGBoost).ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7195,7 +7195,7 @@
71957195
" features = self._features + [self._target]\n",
71967196
"\n",
71977197
" # Retrieve training dataset from Feast\n",
7198-
" dataset = self._feast_batch_client.get_batch_features(\n",
7198+
" dataset = self._feast_batch_client.get_historical_features(\n",
71997199
" feature_refs=features,\n",
72007200
" entity_rows=entity_df).to_dataframe()\n",
72017201
"\n",

‎infra/charts/feast/templates/tests/test-feast-batch-serving.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ spec:
7070
entity_rows_df = df.copy(deep=True).rename(columns={"datetime": "event_timestamp"})[["event_timestamp", "customer_id"]]
7171
pandavro.to_avro("entity_rows.avro", entity_rows_df)
7272
73-
batch_serving_job = client.get_batch_features(
73+
batch_serving_job = client.get_historical_features(
7474
entity_rows="file://entity_rows.avro",
7575
feature_refs=[
7676
f"{project}/daily_transactions:1",

‎sdk/python/feast/client.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import tempfile
2121
import time
2222
import uuid
23+
import warnings
2324
from collections import OrderedDict
2425
from math import ceil
2526
from typing import Dict, List, Optional, Tuple, Union
@@ -547,6 +548,25 @@ def get_batch_features(
547548
entity_rows: Union[pd.DataFrame, str],
548549
compute_statistics: bool = False,
549550
project: str = None,
551+
) -> RetrievalJob:
552+
"""
553+
Deprecated. Please see get_historical_features.
554+
"""
555+
warnings.warn(
556+
"The method get_batch_features() is being deprecated. Please use the identical get_historical_features(). "
557+
"Feast 0.7 and onwards will not support get_batch_features().",
558+
DeprecationWarning,
559+
)
560+
return self.get_historical_features(
561+
feature_refs, entity_rows, compute_statistics, project
562+
)
563+
564+
def get_historical_features(
565+
self,
566+
feature_refs: List[str],
567+
entity_rows: Union[pd.DataFrame, str],
568+
compute_statistics: bool = False,
569+
project: str = None,
550570
) -> RetrievalJob:
551571
"""
552572
Retrieves historical features from a Feast Serving deployment.
@@ -585,7 +605,7 @@ def get_batch_features(
585605
>>> "customer": [1001, 1002, 1003],
586606
>>> }
587607
>>> )
588-
>>> feature_retrieval_job = feast_client.get_batch_features(
608+
>>> feature_retrieval_job = feast_client.get_historical_features(
589609
>>> feature_refs, entity_rows, project="my_project")
590610
>>> df = feature_retrieval_job.to_dataframe()
591611
>>> print(df)

‎sdk/python/tests/test_client.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def test_stop_ingest_job(self, mocked_client, mocker):
610610
"mocked_client",
611611
[pytest.lazy_fixture("mock_client"), pytest.lazy_fixture("secure_mock_client")],
612612
)
613-
def test_get_batch_features(self, mocked_client, mocker):
613+
def test_get_historical_features(self, mocked_client, mocker):
614614

615615
mocked_client._serving_service_stub = Serving.ServingServiceStub(
616616
grpc.insecure_channel("")
@@ -705,7 +705,7 @@ def test_get_batch_features(self, mocked_client, mocker):
705705
# NOTE: Feast Serving does not allow for feature references
706706
# that specify the same feature in the same request.
707707
with patch("google.cloud.storage.Client"):
708-
response = mocked_client.get_batch_features(
708+
response = mocked_client.get_historical_features(
709709
entity_rows=pd.DataFrame(
710710
{
711711
"datetime": [

‎tests/e2e/bq/bq-batch-retrieval.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_batch_apply_all_featuresets(client):
159159
@pytest.mark.direct_runner
160160
@pytest.mark.dataflow_runner
161161
@pytest.mark.run(order=10)
162-
def test_batch_get_batch_features_with_file(client):
162+
def test_batch_get_historical_features_with_file(client):
163163
file_fs1 = client.get_feature_set(name="file_feature_set")
164164

165165
N_ROWS = 10
@@ -193,7 +193,7 @@ def test_batch_get_batch_features_with_file(client):
193193
time.sleep(10)
194194

195195
def check():
196-
feature_retrieval_job = client.get_batch_features(
196+
feature_retrieval_job = client.get_historical_features(
197197
entity_rows="file://file_feature_set.avro",
198198
feature_refs=["feature_value1"],
199199
project=PROJECT_NAME,
@@ -213,7 +213,7 @@ def check():
213213
@pytest.mark.direct_runner
214214
@pytest.mark.dataflow_runner
215215
@pytest.mark.run(order=11)
216-
def test_batch_get_batch_features_with_gs_path(client, gcs_path):
216+
def test_batch_get_historical_features_with_gs_path(client, gcs_path):
217217
gcs_fs1 = client.get_feature_set(name="gcs_feature_set")
218218

219219
N_ROWS = 10
@@ -252,7 +252,7 @@ def test_batch_get_batch_features_with_gs_path(client, gcs_path):
252252
blob.upload_from_filename(file_name)
253253

254254
def check():
255-
feature_retrieval_job = client.get_batch_features(
255+
feature_retrieval_job = client.get_historical_features(
256256
entity_rows=f"{gcs_path}{ts}/*",
257257
feature_refs=["feature_value2"],
258258
project=PROJECT_NAME,
@@ -296,7 +296,7 @@ def test_batch_order_by_creation_time(client):
296296
client.ingest(proc_time_fs, correct_df)
297297

298298
def check():
299-
feature_retrieval_job = client.get_batch_features(
299+
feature_retrieval_job = client.get_historical_features(
300300
entity_rows=incorrect_df[["datetime", "entity_id"]],
301301
feature_refs=["feature_value3"],
302302
project=PROJECT_NAME,
@@ -337,7 +337,7 @@ def test_batch_additional_columns_in_entity_table(client):
337337
)
338338

339339
def check():
340-
feature_retrieval_job = client.get_batch_features(
340+
feature_retrieval_job = client.get_historical_features(
341341
entity_rows=entity_df,
342342
feature_refs=["feature_value4"],
343343
project=PROJECT_NAME,
@@ -392,7 +392,7 @@ def test_batch_point_in_time_correctness_join(client):
392392
client.ingest(historical_fs, historical_df)
393393

394394
def check():
395-
feature_retrieval_job = client.get_batch_features(
395+
feature_retrieval_job = client.get_historical_features(
396396
entity_rows=entity_df,
397397
feature_refs=["feature_value5"],
398398
project=PROJECT_NAME,
@@ -443,7 +443,7 @@ def test_batch_multiple_featureset_joins(client):
443443
# Test retrieve with different variations of the string feature refs
444444
# ie feature set inference for feature refs without specified feature set
445445
def check():
446-
feature_retrieval_job = client.get_batch_features(
446+
feature_retrieval_job = client.get_historical_features(
447447
entity_rows=entity_df,
448448
feature_refs=["feature_value6", "feature_set_2:other_feature_value7"],
449449
project=PROJECT_NAME,
@@ -480,7 +480,7 @@ def test_batch_no_max_age(client):
480480
client.ingest(no_max_age_fs, features_8_df)
481481

482482
def check():
483-
feature_retrieval_job = client.get_batch_features(
483+
feature_retrieval_job = client.get_historical_features(
484484
entity_rows=features_8_df[["datetime", "entity_id"]],
485485
feature_refs=["feature_value8"],
486486
project=PROJECT_NAME,
@@ -564,7 +564,7 @@ def test_update_featureset_apply_featureset_and_ingest_first_subset(
564564
client.ingest(feature_set=update_fs, source=subset_df)
565565

566566
def check():
567-
feature_retrieval_job = client.get_batch_features(
567+
feature_retrieval_job = client.get_historical_features(
568568
entity_rows=update_featureset_dataframe[["datetime", "entity_id"]].iloc[:5],
569569
feature_refs=["update_feature1", "update_feature2"],
570570
project=PROJECT_NAME,
@@ -627,7 +627,7 @@ def test_update_featureset_update_featureset_and_ingest_second_subset(
627627
time.sleep(30)
628628

629629
def check():
630-
feature_retrieval_job = client.get_batch_features(
630+
feature_retrieval_job = client.get_historical_features(
631631
entity_rows=update_featureset_dataframe[["datetime", "entity_id"]].iloc[5:],
632632
feature_refs=["update_feature1", "update_feature3", "update_feature4"],
633633
project=PROJECT_NAME,
@@ -659,7 +659,7 @@ def check():
659659
@pytest.mark.run(order=22)
660660
def test_update_featureset_retrieve_all_fields(client, update_featureset_dataframe):
661661
with pytest.raises(Exception):
662-
feature_retrieval_job = client.get_batch_features(
662+
feature_retrieval_job = client.get_historical_features(
663663
entity_rows=update_featureset_dataframe[["datetime", "entity_id"]],
664664
feature_refs=[
665665
"update_feature1",
@@ -675,7 +675,7 @@ def test_update_featureset_retrieve_all_fields(client, update_featureset_datafra
675675
@pytest.mark.fs_update
676676
@pytest.mark.run(order=23)
677677
def test_update_featureset_retrieve_valid_fields(client, update_featureset_dataframe):
678-
feature_retrieval_job = client.get_batch_features(
678+
feature_retrieval_job = client.get_historical_features(
679679
entity_rows=update_featureset_dataframe[["datetime", "entity_id"]],
680680
feature_refs=["update_feature1", "update_feature3", "update_feature4"],
681681
project=PROJECT_NAME,
@@ -751,7 +751,7 @@ def test_batch_dataset_statistics(client):
751751
break
752752
time.sleep(30)
753753

754-
feature_retrieval_job = client.get_batch_features(
754+
feature_retrieval_job = client.get_historical_features(
755755
entity_rows=entity_df,
756756
feature_refs=["feature_value6", "feature_set_2:other_feature_value7"],
757757
project=PROJECT_NAME,

0 commit comments

Comments
 (0)