Skip to content

Commit 8099ea7

Browse files
Docstrings (#1739)
* Add docstrings to public DataSource methods Signed-off-by: Felix Wang <[email protected]> * Add docstrings to public Entity methods Signed-off-by: Felix Wang <[email protected]> * Add docstrings to public FeatureView methods Signed-off-by: Felix Wang <[email protected]> * Format docs Signed-off-by: Felix Wang <[email protected]> * Add docstrings to public Feature methods Signed-off-by: Felix Wang <[email protected]> * Add docstrings to public FeatureService methods Signed-off-by: Felix Wang <[email protected]> * Add docstrings to public FeatureStore methods Signed-off-by: Felix Wang <[email protected]> * Small fixes Signed-off-by: Felix Wang <[email protected]> * Fix init docstrings Signed-off-by: Felix Wang <[email protected]> * Change MutableMapping to Dict Signed-off-by: Felix Wang <[email protected]> * Change Timestamp to datetime Signed-off-by: Felix Wang <[email protected]>
1 parent 9ae9e3c commit 8099ea7

File tree

9 files changed

+315
-170
lines changed

9 files changed

+315
-170
lines changed

sdk/python/docs/source/index.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Feast Python API Documentation
33

44

55
Feature Store
6-
---------------------------
6+
==================
77

88
.. automodule:: feast.feature_store
99
:members:
@@ -45,3 +45,10 @@ Feature
4545
.. automodule:: feast.feature
4646
:inherited-members:
4747
:members:
48+
49+
Feature Service
50+
==================
51+
52+
.. automodule:: feast.feature_service
53+
:inherited-members:
54+
:members:

sdk/python/feast/data_source.py

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import enum
1717
from abc import ABC, abstractmethod
18-
from typing import Callable, Dict, Iterable, Optional, Tuple
18+
from typing import Any, Callable, Dict, Iterable, Optional, Tuple
1919

2020
from feast import type_map
2121
from feast.data_format import StreamFormat
@@ -220,20 +220,42 @@ def to_proto(self) -> DataSourceProto.KinesisOptions:
220220

221221
class DataSource(ABC):
222222
"""
223-
DataSource that can be used source features
223+
DataSource that can be used to source features.
224+
225+
Args:
226+
event_timestamp_column (optional): Event timestamp column used for point in time
227+
joins of feature values.
228+
created_timestamp_column (optional): Timestamp column indicating when the row
229+
was created, used for deduplicating rows.
230+
field_mapping (optional): A dictionary mapping of column names in this data
231+
source to feature names in a feature table or view. Only used for feature
232+
columns, not entity or timestamp columns.
233+
date_partition_column (optional): Timestamp column used for partitioning.
224234
"""
225235

236+
_event_timestamp_column: str
237+
_created_timestamp_column: str
238+
_field_mapping: Dict[str, str]
239+
_date_partition_column: str
240+
226241
def __init__(
227242
self,
228-
event_timestamp_column: Optional[str] = "",
229-
created_timestamp_column: Optional[str] = "",
243+
event_timestamp_column: Optional[str] = None,
244+
created_timestamp_column: Optional[str] = None,
230245
field_mapping: Optional[Dict[str, str]] = None,
231-
date_partition_column: Optional[str] = "",
246+
date_partition_column: Optional[str] = None,
232247
):
233-
self._event_timestamp_column = event_timestamp_column
234-
self._created_timestamp_column = created_timestamp_column
248+
"""Creates a DataSource object."""
249+
self._event_timestamp_column = (
250+
event_timestamp_column if event_timestamp_column else ""
251+
)
252+
self._created_timestamp_column = (
253+
created_timestamp_column if created_timestamp_column else ""
254+
)
235255
self._field_mapping = field_mapping if field_mapping else {}
236-
self._date_partition_column = date_partition_column
256+
self._date_partition_column = (
257+
date_partition_column if date_partition_column else ""
258+
)
237259

238260
def __eq__(self, other):
239261
if not isinstance(other, DataSource):
@@ -250,68 +272,76 @@ def __eq__(self, other):
250272
return True
251273

252274
@property
253-
def field_mapping(self):
275+
def field_mapping(self) -> Dict[str, str]:
254276
"""
255-
Returns the field mapping of this data source
277+
Returns the field mapping of this data source.
256278
"""
257279
return self._field_mapping
258280

259281
@field_mapping.setter
260282
def field_mapping(self, field_mapping):
261283
"""
262-
Sets the field mapping of this data source
284+
Sets the field mapping of this data source.
263285
"""
264286
self._field_mapping = field_mapping
265287

266288
@property
267-
def event_timestamp_column(self):
289+
def event_timestamp_column(self) -> str:
268290
"""
269-
Returns the event timestamp column of this data source
291+
Returns the event timestamp column of this data source.
270292
"""
271293
return self._event_timestamp_column
272294

273295
@event_timestamp_column.setter
274296
def event_timestamp_column(self, event_timestamp_column):
275297
"""
276-
Sets the event timestamp column of this data source
298+
Sets the event timestamp column of this data source.
277299
"""
278300
self._event_timestamp_column = event_timestamp_column
279301

280302
@property
281-
def created_timestamp_column(self):
303+
def created_timestamp_column(self) -> str:
282304
"""
283-
Returns the created timestamp column of this data source
305+
Returns the created timestamp column of this data source.
284306
"""
285307
return self._created_timestamp_column
286308

287309
@created_timestamp_column.setter
288310
def created_timestamp_column(self, created_timestamp_column):
289311
"""
290-
Sets the created timestamp column of this data source
312+
Sets the created timestamp column of this data source.
291313
"""
292314
self._created_timestamp_column = created_timestamp_column
293315

294316
@property
295-
def date_partition_column(self):
317+
def date_partition_column(self) -> str:
296318
"""
297-
Returns the date partition column of this data source
319+
Returns the date partition column of this data source.
298320
"""
299321
return self._date_partition_column
300322

301323
@date_partition_column.setter
302324
def date_partition_column(self, date_partition_column):
303325
"""
304-
Sets the date partition column of this data source
326+
Sets the date partition column of this data source.
305327
"""
306328
self._date_partition_column = date_partition_column
307329

308330
@staticmethod
309331
@abstractmethod
310-
def from_proto(data_source: DataSourceProto):
311-
"""
312-
Convert data source config in FeatureTable spec to a DataSource class object.
332+
def from_proto(data_source: DataSourceProto) -> Any:
313333
"""
334+
Converts data source config in FeatureTable spec to a DataSource class object.
314335
336+
Args:
337+
data_source: A protobuf representation of a DataSource.
338+
339+
Returns:
340+
A DataSource class object.
341+
342+
Raises:
343+
ValueError: The type of DataSource could not be identified.
344+
"""
315345
if data_source.data_source_class_type:
316346
cls = get_data_source_class_from_type(data_source.data_source_class_type)
317347
return cls.from_proto(data_source)
@@ -343,7 +373,7 @@ def from_proto(data_source: DataSourceProto):
343373
):
344374
data_source_obj = KinesisSource.from_proto(data_source)
345375
else:
346-
raise ValueError("Could not identify the source type being added")
376+
raise ValueError("Could not identify the source type being added.")
347377

348378
return data_source_obj
349379

@@ -357,27 +387,35 @@ def to_proto(self) -> DataSourceProto:
357387
def validate(self, config: RepoConfig):
358388
"""
359389
Validates the underlying data source.
390+
391+
Args:
392+
config: Configuration object used to configure a feature store.
360393
"""
361394
raise NotImplementedError
362395

363396
@staticmethod
364397
@abstractmethod
365398
def source_datatype_to_feast_value_type() -> Callable[[str], ValueType]:
366399
"""
367-
Get the callable method that returns Feast type given the raw column type
400+
Returns the callable method that returns Feast type given the raw column type.
368401
"""
369402
raise NotImplementedError
370403

371404
def get_table_column_names_and_types(
372405
self, config: RepoConfig
373406
) -> Iterable[Tuple[str, str]]:
374407
"""
375-
Get the list of column names and raw column types
408+
Returns the list of column names and raw column types.
409+
410+
Args:
411+
config: Configuration object used to configure a feature store.
376412
"""
377413
raise NotImplementedError
378414

379415
def get_table_query_string(self) -> str:
380-
"""Returns a string that can directly be used to reference this table in SQL"""
416+
"""
417+
Returns a string that can directly be used to reference this table in SQL.
418+
"""
381419
raise NotImplementedError
382420

383421

0 commit comments

Comments
 (0)