Skip to content

Commit e610f62

Browse files
chore: Add docstrings (feast-dev#3128)
* Fix base feature view docstring Signed-off-by: Felix Wang <[email protected]> * Add docstring to trino source Signed-off-by: Felix Wang <[email protected]> * Fix docstrings for bfv and sfv Signed-off-by: Felix Wang <[email protected]> * Temp work Signed-off-by: Felix Wang <[email protected]> * Update data source docstrings Signed-off-by: Felix Wang <[email protected]> Signed-off-by: Felix Wang <[email protected]>
1 parent f0594e1 commit e610f62

File tree

9 files changed

+100
-30
lines changed

9 files changed

+100
-30
lines changed

sdk/python/feast/base_feature_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class BaseFeatureView(ABC):
3535
maintainer.
3636
projection: The feature view projection storing modifications to be applied to
3737
this base feature view at retrieval time.
38-
created_timestamp (optional): The time when the base feature view was created.
39-
last_updated_timestamp (optional): The time when the base feature view was last
38+
created_timestamp: The time when the base feature view was created.
39+
last_updated_timestamp: The time when the base feature view was last
4040
updated.
4141
"""
4242

sdk/python/feast/batch_feature_view.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
from datetime import timedelta
2-
from typing import Dict, List, Optional, Union
1+
import warnings
2+
from datetime import datetime, timedelta
3+
from typing import Dict, List, Optional, Tuple, Union
34

5+
from feast import flags_helper
46
from feast.data_source import DataSource
57
from feast.entity import Entity
68
from feast.feature_view import FeatureView
79
from feast.field import Field
810
from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto
911

12+
warnings.simplefilter("once", RuntimeWarning)
13+
1014
SUPPORTED_BATCH_SOURCES = {
1115
"BigQuerySource",
1216
"FileSource",
@@ -19,22 +23,58 @@
1923

2024

2125
class BatchFeatureView(FeatureView):
26+
"""
27+
A batch feature view defines a logical group of features that has only a batch data source.
28+
29+
Attributes:
30+
name: The unique name of the batch feature view.
31+
entities: List of entities or entity join keys.
32+
ttl: The amount of time this group of features lives. A ttl of 0 indicates that
33+
this group of features lives forever. Note that large ttl's or a ttl of 0
34+
can result in extremely computationally intensive queries.
35+
schema: The schema of the feature view, including feature, timestamp, and entity
36+
columns. If not specified, can be inferred from the underlying data source.
37+
source: The batch source of data where this group of features is stored.
38+
online: A boolean indicating whether online retrieval is enabled for this feature view.
39+
description: A human-readable description.
40+
tags: A dictionary of key-value pairs to store arbitrary metadata.
41+
owner: The owner of the batch feature view, typically the email of the primary maintainer.
42+
"""
43+
44+
name: str
45+
entities: List[str]
46+
ttl: Optional[timedelta]
47+
source: DataSource
48+
schema: List[Field]
49+
entity_columns: List[Field]
50+
features: List[Field]
51+
online: bool
52+
description: str
53+
tags: Dict[str, str]
54+
owner: str
55+
timestamp_field: str
56+
materialization_intervals: List[Tuple[datetime, datetime]]
57+
2258
def __init__(
2359
self,
2460
*,
25-
name: Optional[str] = None,
61+
name: str,
62+
source: DataSource,
2663
entities: Optional[Union[List[Entity], List[str]]] = None,
2764
ttl: Optional[timedelta] = None,
2865
tags: Optional[Dict[str, str]] = None,
2966
online: bool = True,
3067
description: str = "",
3168
owner: str = "",
3269
schema: Optional[List[Field]] = None,
33-
source: Optional[DataSource] = None,
3470
):
71+
if not flags_helper.is_test():
72+
warnings.warn(
73+
"Batch feature views are experimental features in alpha development. "
74+
"Some functionality may still be unstable so functionality can change in the future.",
75+
RuntimeWarning,
76+
)
3577

36-
if source is None:
37-
raise ValueError("Feature views need a source specified")
3878
if (
3979
type(source).__name__ not in SUPPORTED_BATCH_SOURCES
4080
and source.to_proto().type != DataSourceProto.SourceType.CUSTOM_SOURCE

sdk/python/feast/infra/offline_stores/bigquery_source.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ def __init__(
3636
"""Create a BigQuerySource from an existing table or query.
3737
3838
Args:
39-
name (optional): Name for the source. Defaults to the table if not specified.
39+
name (optional): Name for the source. Defaults to the table if not specified, in which
40+
case the table must be specified.
4041
timestamp_field (optional): Event timestamp field used for point in time
4142
joins of feature values.
43+
table (optional): BigQuery table where the features are stored. Exactly one of 'table'
44+
and 'query' must be specified.
4245
table (optional): The BigQuery table where features can be found.
4346
created_timestamp_column (optional): Timestamp column when row was created, used for deduplicating rows.
4447
field_mapping (optional): A dictionary mapping of column names in this data source to feature names in a feature table
4548
or view. Only used for feature columns, not entities or timestamp columns.
46-
query (optional): SQL query to execute to generate data for this data source.
49+
query (optional): The query to be executed to obtain the features. Exactly one of 'table'
50+
and 'query' must be specified.
4751
description (optional): A human-readable description.
4852
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
4953
owner (optional): The owner of the bigquery source, typically the email of the primary

sdk/python/feast/infra/offline_stores/contrib/athena_offline_store/athena_source.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ def __init__(
3838
3939
Args:
4040
timestamp_field : event timestamp column.
41-
table (optional): Athena table where the features are stored.
41+
table (optional): Athena table where the features are stored. Exactly one of 'table'
42+
and 'query' must be specified.
4243
database: Athena Database Name
4344
data_source (optional): Athena data source
4445
created_timestamp_column (optional): Timestamp column indicating when the
4546
row was created, used for deduplicating rows.
4647
field_mapping (optional): A dictionary mapping of column names in this data
4748
source to column names in a feature table or view.
4849
date_partition_column : Timestamp column used for partitioning.
49-
query (optional): The query to be executed to obtain the features.
50-
name (optional): Name for the source. Defaults to the table_ref if not specified.
50+
query (optional): The query to be executed to obtain the features. Exactly one of 'table'
51+
and 'query' must be specified.
52+
name (optional): Name for the source. Defaults to the table if not specified, in which
53+
case the table must be specified.
5154
description (optional): A human-readable description.
5255
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
5356
owner (optional): The owner of the athena source, typically the email of the primary
5457
maintainer.
55-
56-
5758
"""
58-
5959
_database = "default" if table and not database else database
6060
self.athena_options = AthenaOptions(
6161
table=table, query=query, database=_database, data_source=data_source

sdk/python/feast/infra/offline_stores/contrib/trino_offline_store/trino_source.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ def __init__(
9797
tags: Optional[Dict[str, str]] = None,
9898
owner: Optional[str] = "",
9999
):
100+
"""
101+
Creates a TrinoSource object.
102+
103+
Args:
104+
name (optional): Name for the source. Defaults to the table if not specified, in which
105+
case the table must be specified.
106+
timestamp_field (optional): Event timestamp field used for point in time
107+
joins of feature values.
108+
table (optional): Trino table where the features are stored. Exactly one of 'table' and
109+
'query' must be specified.
110+
created_timestamp_column (optional): Timestamp column indicating when the
111+
row was created, used for deduplicating rows.
112+
field_mapping (optional): A dictionary mapping of column names in this data
113+
source to column names in a feature table or view.
114+
query (optional): The query to be executed to obtain the features. Exactly one of 'table'
115+
and 'query' must be specified.
116+
description (optional): A human-readable description.
117+
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
118+
owner (optional): The owner of the snowflake source, typically the email of the primary
119+
maintainer.
120+
"""
100121
# If no name, use the table as the default name.
101122
if name is None and table is None:
102123
raise DataSourceNoNameException()

sdk/python/feast/infra/offline_stores/redshift_source.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ def __init__(
4343
Creates a RedshiftSource object.
4444
4545
Args:
46-
name (optional): Name for the source. Defaults to the table_ref if not specified.
46+
name (optional): Name for the source. Defaults to the table if not specified, in which
47+
case the table must be specified.
4748
timestamp_field (optional): Event timestamp field used for point in time
4849
joins of feature values.
49-
table (optional): Redshift table where the features are stored.
50+
table (optional): Redshift table where the features are stored. Exactly one of 'table'
51+
and 'query' must be specified.
5052
schema (optional): Redshift schema in which the table is located.
5153
created_timestamp_column (optional): Timestamp column indicating when the
5254
row was created, used for deduplicating rows.
5355
field_mapping (optional): A dictionary mapping of column names in this data
5456
source to column names in a feature table or view.
55-
query (optional): The query to be executed to obtain the features.
57+
query (optional): The query to be executed to obtain the features. Exactly one of 'table'
58+
and 'query' must be specified.
5659
description (optional): A human-readable description.
5760
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
5861
owner (optional): The owner of the redshift source, typically the email of the primary

sdk/python/feast/infra/offline_stores/snowflake_source.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ def __init__(
4040
Creates a SnowflakeSource object.
4141
4242
Args:
43-
name (optional): Name for the source. Defaults to the table if not specified.
43+
name (optional): Name for the source. Defaults to the table if not specified, in which
44+
case the table must be specified.
4445
timestamp_field (optional): Event timestamp field used for point in time
4546
joins of feature values.
4647
database (optional): Snowflake database where the features are stored.
4748
warehouse (optional): Snowflake warehouse where the database is stored.
4849
schema (optional): Snowflake schema in which the table is located.
49-
table (optional): Snowflake table where the features are stored.
50-
query (optional): The query to be executed to obtain the features.
50+
table (optional): Snowflake table where the features are stored. Exactly one of 'table'
51+
and 'query' must be specified.
52+
query (optional): The query to be executed to obtain the features. Exactly one of 'table'
53+
and 'query' must be specified.
5154
created_timestamp_column (optional): Timestamp column indicating when the
5255
row was created, used for deduplicating rows.
5356
field_mapping (optional): A dictionary mapping of column names in this data

sdk/python/feast/stream_feature_view.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
@typechecked
3434
class StreamFeatureView(FeatureView):
3535
"""
36-
NOTE: Stream Feature Views are not yet fully implemented and exist to allow users to register their stream sources and
37-
schemas with Feast.
36+
A stream feature view defines a logical group of features that has both a stream data source and
37+
a batch data source.
3838
3939
Attributes:
4040
name: The unique name of the stream feature view.
@@ -44,15 +44,14 @@ class StreamFeatureView(FeatureView):
4444
can result in extremely computationally intensive queries.
4545
schema: The schema of the feature view, including feature, timestamp, and entity
4646
columns. If not specified, can be inferred from the underlying data source.
47-
source: DataSource. The stream source of data where this group of features is stored.
47+
source: The stream source of data where this group of features is stored.
4848
aggregations: List of aggregations registered with the stream feature view.
4949
mode: The mode of execution.
5050
timestamp_field: Must be specified if aggregations are specified. Defines the timestamp column on which to aggregate windows.
51-
online: Defines whether this stream feature view is used in online feature retrieval.
51+
online: A boolean indicating whether online retrieval is enabled for this feature view.
5252
description: A human-readable description.
5353
tags: A dictionary of key-value pairs to store arbitrary metadata.
54-
owner: The owner of the on demand feature view, typically the email of the primary
55-
maintainer.
54+
owner: The owner of the stream feature view, typically the email of the primary maintainer.
5655
udf: The user defined transformation function. This transformation function should have all of the corresponding imports imported within the function.
5756
"""
5857

@@ -92,7 +91,7 @@ def __init__(
9291
):
9392
if not flags_helper.is_test():
9493
warnings.warn(
95-
"Stream Feature Views are experimental features in alpha development. "
94+
"Stream feature views are experimental features in alpha development. "
9695
"Some functionality may still be unstable so functionality can change in the future.",
9796
RuntimeWarning,
9897
)

sdk/python/tests/unit/test_feature_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_create_batch_feature_view():
2424
source=batch_source,
2525
)
2626

27-
with pytest.raises(ValueError):
27+
with pytest.raises(TypeError):
2828
BatchFeatureView(
2929
name="test batch feature view", entities=[], ttl=timedelta(days=30)
3030
)

0 commit comments

Comments
 (0)