From de8a1b6af032d745aa5234ee6418e2cdfce3e49f Mon Sep 17 00:00:00 2001 From: Felix Wang Date: Thu, 29 Jul 2021 13:53:16 -0700 Subject: [PATCH] Restore feature refs (#1746) * Ensure the features argument is not breaking Signed-off-by: Felix Wang * Show DeprecationWarning for FeatureView input parameter only when necessary Signed-off-by: Felix Wang --- sdk/python/feast/feature_store.py | 26 +++++++++++++++++-- sdk/python/feast/feature_view.py | 15 ++++++----- .../registration/test_feature_store.py | 4 +-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/sdk/python/feast/feature_store.py b/sdk/python/feast/feature_store.py index 037d6b588c..fcff721257 100644 --- a/sdk/python/feast/feature_store.py +++ b/sdk/python/feast/feature_store.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import warnings from collections import Counter, OrderedDict, defaultdict from datetime import datetime, timedelta from pathlib import Path @@ -43,6 +44,8 @@ from feast.usage import log_exceptions, log_exceptions_and_usage from feast.version import get_version +warnings.simplefilter("once", DeprecationWarning) + class FeatureStore: """ @@ -219,7 +222,7 @@ def delete_feature_view(self, name: str): def _get_features( self, - features: Union[List[str], FeatureService], + features: Optional[Union[List[str], FeatureService]], feature_refs: Optional[List[str]], ) -> List[str]: _features = features or feature_refs @@ -342,7 +345,7 @@ def teardown(self): def get_historical_features( self, entity_df: Union[pd.DataFrame, str], - features: Union[List[str], FeatureService], + features: Optional[Union[List[str], FeatureService]] = None, feature_refs: Optional[List[str]] = None, full_feature_names: bool = False, ) -> RetrievalJob: @@ -374,6 +377,9 @@ def get_historical_features( Returns: RetrievalJob which can be used to materialize the results. + Raises: + ValueError: Both or neither of features and feature_refs are specified. + Examples: Retrieve historical features using a BigQuery SQL entity dataframe @@ -387,6 +393,22 @@ def get_historical_features( >>> feature_data = retrieval_job.to_df() >>> model.fit(feature_data) # insert your modeling framework here. """ + if (features is not None and feature_refs is not None) or ( + features is None and feature_refs is None + ): + raise ValueError( + "You must specify exactly one of features and feature_refs." + ) + + if feature_refs: + warnings.warn( + ( + "The argument 'feature_refs' is being deprecated. Please use 'features' " + "instead. Feast 0.13 and onwards will not support the argument 'feature_refs'." + ), + DeprecationWarning, + ) + _feature_refs = self._get_features(features, feature_refs) all_feature_views = self._registry.list_feature_views(project=self.project) diff --git a/sdk/python/feast/feature_view.py b/sdk/python/feast/feature_view.py index 886d19d639..d5d1b2f2ca 100644 --- a/sdk/python/feast/feature_view.py +++ b/sdk/python/feast/feature_view.py @@ -93,13 +93,14 @@ def __init__( Raises: ValueError: A field mapping conflicts with an Entity or a Feature. """ - warnings.warn( - ( - "The argument 'input' is being deprecated. Please use 'batch_source' " - "instead. Feast 0.13 and onwards will not support the argument 'input'." - ), - DeprecationWarning, - ) + if input is not None: + warnings.warn( + ( + "The argument 'input' is being deprecated. Please use 'batch_source' " + "instead. Feast 0.13 and onwards will not support the argument 'input'." + ), + DeprecationWarning, + ) _input = input or batch_source assert _input is not None diff --git a/sdk/python/tests/integration/registration/test_feature_store.py b/sdk/python/tests/integration/registration/test_feature_store.py index 81f443a630..c90131f7f8 100644 --- a/sdk/python/tests/integration/registration/test_feature_store.py +++ b/sdk/python/tests/integration/registration/test_feature_store.py @@ -490,7 +490,7 @@ def test_apply_duplicated_featureview_names(feature_store_with_local_registry): entities=["driver_id"], ttl=timedelta(seconds=10), online=False, - input=FileSource(path="driver_stats.parquet"), + batch_source=FileSource(path="driver_stats.parquet"), tags={}, ) @@ -499,7 +499,7 @@ def test_apply_duplicated_featureview_names(feature_store_with_local_registry): entities=["id"], ttl=timedelta(seconds=10), online=False, - input=FileSource(path="customer_stats.parquet"), + batch_source=FileSource(path="customer_stats.parquet"), tags={}, ) try: