wedata-feature-engineering 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wedata/__init__.py +1 -1
- wedata/feature_store/client.py +113 -41
- wedata/feature_store/constants/constants.py +19 -0
- wedata/feature_store/entities/column_info.py +4 -4
- wedata/feature_store/entities/feature_lookup.py +5 -1
- wedata/feature_store/entities/feature_spec.py +46 -46
- wedata/feature_store/entities/feature_table.py +42 -99
- wedata/feature_store/entities/training_set.py +13 -12
- wedata/feature_store/feature_table_client/feature_table_client.py +86 -31
- wedata/feature_store/spark_client/spark_client.py +30 -56
- wedata/feature_store/training_set_client/training_set_client.py +209 -38
- wedata/feature_store/utils/common_utils.py +213 -3
- wedata/feature_store/utils/feature_lookup_utils.py +6 -6
- wedata/feature_store/utils/feature_spec_utils.py +6 -6
- wedata/feature_store/utils/feature_utils.py +5 -5
- wedata/feature_store/utils/on_demand_utils.py +107 -0
- wedata/feature_store/utils/schema_utils.py +1 -1
- wedata/feature_store/utils/signature_utils.py +205 -0
- wedata/feature_store/utils/training_set_utils.py +18 -19
- wedata/feature_store/utils/uc_utils.py +1 -1
- {wedata_feature_engineering-0.1.5.dist-info → wedata_feature_engineering-0.1.7.dist-info}/METADATA +1 -1
- wedata_feature_engineering-0.1.7.dist-info/RECORD +43 -0
- feature_store/__init__.py +0 -6
- feature_store/client.py +0 -169
- feature_store/constants/__init__.py +0 -0
- feature_store/constants/constants.py +0 -28
- feature_store/entities/__init__.py +0 -0
- feature_store/entities/column_info.py +0 -117
- feature_store/entities/data_type.py +0 -92
- feature_store/entities/environment_variables.py +0 -55
- feature_store/entities/feature.py +0 -53
- feature_store/entities/feature_column_info.py +0 -64
- feature_store/entities/feature_function.py +0 -55
- feature_store/entities/feature_lookup.py +0 -179
- feature_store/entities/feature_spec.py +0 -454
- feature_store/entities/feature_spec_constants.py +0 -25
- feature_store/entities/feature_table.py +0 -164
- feature_store/entities/feature_table_info.py +0 -40
- feature_store/entities/function_info.py +0 -184
- feature_store/entities/on_demand_column_info.py +0 -44
- feature_store/entities/source_data_column_info.py +0 -21
- feature_store/entities/training_set.py +0 -134
- feature_store/feature_table_client/__init__.py +0 -0
- feature_store/feature_table_client/feature_table_client.py +0 -313
- feature_store/spark_client/__init__.py +0 -0
- feature_store/spark_client/spark_client.py +0 -286
- feature_store/training_set_client/__init__.py +0 -0
- feature_store/training_set_client/training_set_client.py +0 -196
- feature_store/utils/__init__.py +0 -0
- feature_store/utils/common_utils.py +0 -96
- feature_store/utils/feature_lookup_utils.py +0 -570
- feature_store/utils/feature_spec_utils.py +0 -286
- feature_store/utils/feature_utils.py +0 -73
- feature_store/utils/schema_utils.py +0 -117
- feature_store/utils/topological_sort.py +0 -158
- feature_store/utils/training_set_utils.py +0 -580
- feature_store/utils/uc_utils.py +0 -281
- feature_store/utils/utils.py +0 -252
- feature_store/utils/validation_utils.py +0 -55
- wedata/feature_store/utils/utils.py +0 -252
- wedata_feature_engineering-0.1.5.dist-info/RECORD +0 -79
- {wedata_feature_engineering-0.1.5.dist-info → wedata_feature_engineering-0.1.7.dist-info}/WHEEL +0 -0
- {wedata_feature_engineering-0.1.5.dist-info → wedata_feature_engineering-0.1.7.dist-info}/top_level.txt +0 -0
@@ -1,64 +0,0 @@
|
|
1
|
-
from typing import List, Optional
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class FeatureColumnInfo:
|
6
|
-
def __init__(
|
7
|
-
self,
|
8
|
-
table_name: str,
|
9
|
-
feature_name: str,
|
10
|
-
lookup_key: List[str],
|
11
|
-
output_name: str,
|
12
|
-
timestamp_lookup_key: Optional[List[str]] = None,
|
13
|
-
):
|
14
|
-
if timestamp_lookup_key is None:
|
15
|
-
timestamp_lookup_key = []
|
16
|
-
if not table_name:
|
17
|
-
raise ValueError("table_name must be non-empty.")
|
18
|
-
if not feature_name:
|
19
|
-
raise ValueError("feature_name must be non-empty.")
|
20
|
-
if not isinstance(lookup_key, list):
|
21
|
-
raise ValueError("lookup_key must be a list.")
|
22
|
-
if not lookup_key or "" in lookup_key or None in lookup_key:
|
23
|
-
raise ValueError("lookup_key must be non-empty.")
|
24
|
-
if not output_name:
|
25
|
-
raise ValueError("output_name must be non-empty.")
|
26
|
-
if not isinstance(timestamp_lookup_key, list):
|
27
|
-
raise ValueError("timestamp_lookup_key must be a list.")
|
28
|
-
|
29
|
-
self._table_name = table_name
|
30
|
-
self._feature_name = feature_name
|
31
|
-
self._lookup_key = lookup_key
|
32
|
-
self._output_name = output_name
|
33
|
-
self._timestamp_lookup_key = timestamp_lookup_key
|
34
|
-
|
35
|
-
@property
|
36
|
-
def table_name(self):
|
37
|
-
return self._table_name
|
38
|
-
|
39
|
-
@property
|
40
|
-
def lookup_key(self):
|
41
|
-
return self._lookup_key
|
42
|
-
|
43
|
-
@property
|
44
|
-
def feature_name(self):
|
45
|
-
return self._feature_name
|
46
|
-
|
47
|
-
@property
|
48
|
-
def output_name(self):
|
49
|
-
return self._output_name
|
50
|
-
|
51
|
-
@property
|
52
|
-
def timestamp_lookup_key(self):
|
53
|
-
return self._timestamp_lookup_key
|
54
|
-
|
55
|
-
@classmethod
|
56
|
-
def from_proto(cls, feature_column_info_proto):
|
57
|
-
return cls(
|
58
|
-
table_name=feature_column_info_proto.table_name,
|
59
|
-
feature_name=feature_column_info_proto.feature_name,
|
60
|
-
lookup_key=list(feature_column_info_proto.lookup_key),
|
61
|
-
output_name=feature_column_info_proto.output_name,
|
62
|
-
timestamp_lookup_key=list(feature_column_info_proto.timestamp_lookup_key),
|
63
|
-
)
|
64
|
-
|
@@ -1,55 +0,0 @@
|
|
1
|
-
from typing import Dict, Optional
|
2
|
-
|
3
|
-
|
4
|
-
class FeatureFunction:
|
5
|
-
|
6
|
-
"""
|
7
|
-
特征方法类
|
8
|
-
|
9
|
-
特征方法是用户定义的函数,用于将特征表中的特征组合成新特征,特征方法可以是任何用户定义的函数,例如Python UDF。
|
10
|
-
|
11
|
-
特征方法类有以下属性:
|
12
|
-
- udf_name:要调用的Python UDF的名称。
|
13
|
-
- input_bindings:用于将Python UDF的输入映射到训练集中的特征的字典。
|
14
|
-
- output_name:如果提供,则会将此特征重命名为 :meth:`create_training_set() <databricks.feature_engineering.client.FeatureEngineeringClient.create_training_set>` 返回的 :class:`TrainingSet <databricks.ml_features.training_set.TrainingSet>` 中的特征。
|
15
|
-
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(
|
19
|
-
self,
|
20
|
-
*,
|
21
|
-
udf_name: str,
|
22
|
-
input_bindings: Optional[Dict[str, str]] = None,
|
23
|
-
output_name: Optional[str] = None,
|
24
|
-
):
|
25
|
-
"""Initialize a FeatureFunction object. See class documentation."""
|
26
|
-
# UC function names are always lowercase.
|
27
|
-
self._udf_name = udf_name.lower()
|
28
|
-
self._input_bindings = input_bindings if input_bindings else {}
|
29
|
-
self._output_name = output_name
|
30
|
-
|
31
|
-
@property
|
32
|
-
def udf_name(self) -> str:
|
33
|
-
"""
|
34
|
-
The name of the Python UDF called by this FeatureFunction.
|
35
|
-
"""
|
36
|
-
return self._udf_name
|
37
|
-
|
38
|
-
@property
|
39
|
-
def input_bindings(self) -> Dict[str, str]:
|
40
|
-
"""
|
41
|
-
The input to use for each argument of the Python UDF.
|
42
|
-
|
43
|
-
For example:
|
44
|
-
|
45
|
-
`{"x": "feature1", "y": "input1"}`
|
46
|
-
"""
|
47
|
-
return self._input_bindings
|
48
|
-
|
49
|
-
@property
|
50
|
-
def output_name(self) -> Optional[str]:
|
51
|
-
"""
|
52
|
-
The output name to use for the results of this FeatureFunction.
|
53
|
-
If empty, defaults to the fully qualified `udf_name` when evaluated.
|
54
|
-
"""
|
55
|
-
return self._output_name
|
@@ -1,179 +0,0 @@
|
|
1
|
-
import copy
|
2
|
-
import datetime
|
3
|
-
import logging
|
4
|
-
from typing import Dict, List, Optional, Union
|
5
|
-
|
6
|
-
from feature_store.utils import common_utils
|
7
|
-
|
8
|
-
_logger = logging.getLogger(__name__)
|
9
|
-
|
10
|
-
|
11
|
-
class FeatureLookup:
|
12
|
-
|
13
|
-
"""
|
14
|
-
特征查找类
|
15
|
-
|
16
|
-
特征查找类用于指定特征表中的特征,并将其与训练集中的特征进行关联。
|
17
|
-
|
18
|
-
特征查找类有以下属性:
|
19
|
-
|
20
|
-
- table_name:特征表的名称。
|
21
|
-
- lookup_key:用于在特征表和训练集之间进行联接的键。lookup_key必须是训练集中的列。lookup_key的类型和顺序必须与特征表的主键匹配。
|
22
|
-
- feature_names:要从特征表中查找的特征的名称。如果您的模型需要主键作为特征,则可以将它们声明为独立的FeatureLookups。
|
23
|
-
- rename_outputs:如果提供,则会将特征重命名为 :meth:`create_training_set() <databricks.feature_engineering.client.FeatureEngineeringClient.create_training_set>`返回的 :class:`TrainingSet <databricks.ml_features.training_set.TrainingSet>` 中的特征。
|
24
|
-
- timestamp_lookup_key:用于在特征表和训练集之间进行联接的时间戳键。timestamp_lookup_key必须是训练集中的列。timestamp_lookup_key的类型必须与特征表的时间戳键的类型匹配。
|
25
|
-
- lookback_window: 当对特征表执行时间点查找时使用的回溯窗口,该查找针对传递给 :meth:`create_training_set() <databricks.feature_engineering.client.FeatureEngineeringClient.create_training_set>` 方法的数据帧。特征存储将检索在数据帧的``timestamp_lookup_key``指定时间戳之前且在``lookback_window``时间范围内的最新特征值,如果不存在这样的特征值则返回null。当设置为0时,仅返回特征表中的精确匹配项。
|
26
|
-
- feature_name:特征名称。**已弃用**。使用 `feature_names`。
|
27
|
-
- output_name:如果提供,则会将此特征重命名为 :meth:`create_training_set() <databricks.feature_engineering.client.FeatureEngineeringClient.create_training_set>` 返回的 :class:`TrainingSet <databricks.ml_features.training_set.TrainingSet>` 中的特征。**已弃用**。使用 `rename_outputs`。
|
28
|
-
|
29
|
-
示例:
|
30
|
-
|
31
|
-
from databricks.feature_store import FeatureLookup
|
32
|
-
|
33
|
-
lookup = FeatureLookup(
|
34
|
-
table_name="my_feature_table",
|
35
|
-
lookup_key="my_lookup_key",
|
36
|
-
feature_names=["my_feature_1", "my_feature_2"],
|
37
|
-
rename_outputs={"my_feature_1": "my_feature_1_renamed"},
|
38
|
-
timestamp_lookup_key="my_timestamp_lookup_key",
|
39
|
-
lookback_window=datetime.timedelta(days=1)
|
40
|
-
)
|
41
|
-
|
42
|
-
"""
|
43
|
-
|
44
|
-
def __init__(
|
45
|
-
self,
|
46
|
-
table_name: str,
|
47
|
-
lookup_key: Union[str, List[str]],
|
48
|
-
*,
|
49
|
-
feature_names: Union[str, List[str], None] = None,
|
50
|
-
rename_outputs: Optional[Dict[str, str]] = None,
|
51
|
-
timestamp_lookup_key: Optional[str] = None,
|
52
|
-
lookback_window: Optional[datetime.timedelta] = None,
|
53
|
-
**kwargs,
|
54
|
-
):
|
55
|
-
"""Initialize a FeatureLookup object. See class documentation."""
|
56
|
-
|
57
|
-
self._feature_name_deprecated = kwargs.pop("feature_name", None)
|
58
|
-
self._output_name_deprecated = kwargs.pop("output_name", None)
|
59
|
-
|
60
|
-
if kwargs:
|
61
|
-
raise TypeError(
|
62
|
-
f"FeatureLookup got unexpected keyword argument(s): {list(kwargs.keys())}"
|
63
|
-
)
|
64
|
-
|
65
|
-
self._table_name = table_name
|
66
|
-
|
67
|
-
if type(timestamp_lookup_key) is list:
|
68
|
-
if len(timestamp_lookup_key) == 0:
|
69
|
-
timestamp_lookup_key = None
|
70
|
-
elif len(timestamp_lookup_key) == 1:
|
71
|
-
timestamp_lookup_key = timestamp_lookup_key[0]
|
72
|
-
else:
|
73
|
-
raise ValueError(
|
74
|
-
f"Setting multiple timestamp lookup keys is not supported."
|
75
|
-
)
|
76
|
-
|
77
|
-
if rename_outputs is not None and not isinstance(rename_outputs, dict):
|
78
|
-
raise ValueError(
|
79
|
-
f"Unexpected type for rename_outputs: {type(rename_outputs)}"
|
80
|
-
)
|
81
|
-
|
82
|
-
self._feature_names = common_utils.as_list(feature_names, default=[])
|
83
|
-
|
84
|
-
# Make sure the user didn't accidentally pass in any nested lists/dicts in feature_names
|
85
|
-
for fn in self._feature_names:
|
86
|
-
if not isinstance(fn, str):
|
87
|
-
raise ValueError(
|
88
|
-
f"Unexpected type for element in feature_names: {type(self._feature_names)}, only strings allowed in list"
|
89
|
-
)
|
90
|
-
|
91
|
-
if lookback_window is not None:
|
92
|
-
if not timestamp_lookup_key:
|
93
|
-
raise ValueError(
|
94
|
-
f"Unexpected lookback_window value: {lookback_window}, lookback windows can only be applied on time series "
|
95
|
-
f"feature tables. Use timestamp_lookup_key to perform point-in-time lookups with lookback window."
|
96
|
-
)
|
97
|
-
if not isinstance(
|
98
|
-
lookback_window, datetime.timedelta
|
99
|
-
) or lookback_window < datetime.timedelta(0):
|
100
|
-
raise ValueError(
|
101
|
-
f"Unexpected value for lookback_window: {lookback_window}, only non-negative datetime.timedelta allowed."
|
102
|
-
)
|
103
|
-
|
104
|
-
self._lookup_key = copy.copy(lookup_key)
|
105
|
-
self._timestamp_lookup_key = copy.copy(timestamp_lookup_key)
|
106
|
-
self._lookback_window = copy.copy(lookback_window)
|
107
|
-
|
108
|
-
self._rename_outputs = {}
|
109
|
-
if rename_outputs is not None:
|
110
|
-
self._rename_outputs = rename_outputs.copy()
|
111
|
-
|
112
|
-
self._inject_deprecated_feature_name()
|
113
|
-
self._inject_deprecated_output_name()
|
114
|
-
|
115
|
-
@property
|
116
|
-
def table_name(self):
|
117
|
-
"""The table name to use in this FeatureLookup."""
|
118
|
-
return self._table_name
|
119
|
-
|
120
|
-
@property
|
121
|
-
def lookup_key(self):
|
122
|
-
"""The lookup key(s) to use in this FeatureLookup."""
|
123
|
-
return self._lookup_key
|
124
|
-
|
125
|
-
@property
|
126
|
-
def feature_name(self):
|
127
|
-
"""The feature name to use in this FeatureLookup. **Deprecated**. Use `feature_names`."""
|
128
|
-
return self._feature_name_deprecated
|
129
|
-
|
130
|
-
@property
|
131
|
-
def feature_names(self):
|
132
|
-
"""The feature names to use in this FeatureLookup."""
|
133
|
-
return self._feature_names
|
134
|
-
|
135
|
-
@property
|
136
|
-
def output_name(self):
|
137
|
-
"""The output name to use in this FeatureLookup. **Deprecated**. Use `feature_names`."""
|
138
|
-
if self._output_name_deprecated:
|
139
|
-
return self._output_name_deprecated
|
140
|
-
else:
|
141
|
-
return self._feature_name_deprecated
|
142
|
-
|
143
|
-
@property
|
144
|
-
def timestamp_lookup_key(self):
|
145
|
-
return self._timestamp_lookup_key
|
146
|
-
|
147
|
-
@property
|
148
|
-
def lookback_window(self):
|
149
|
-
"""A lookback window applied only for point-in-time lookups."""
|
150
|
-
return self._lookback_window
|
151
|
-
|
152
|
-
def _get_feature_names(self):
|
153
|
-
return self._feature_names
|
154
|
-
|
155
|
-
def _get_output_name(self, feature_name):
|
156
|
-
"""Lookup the renamed output, or fallback to the feature name itself if no mapping is present"""
|
157
|
-
return self._rename_outputs.get(feature_name, feature_name)
|
158
|
-
|
159
|
-
def _inject_deprecated_feature_name(self):
|
160
|
-
if self._feature_name_deprecated:
|
161
|
-
if len(self._feature_names) > 0:
|
162
|
-
raise ValueError(
|
163
|
-
"Use either feature_names or feature_name parameter, but not both."
|
164
|
-
)
|
165
|
-
_logger.warning(
|
166
|
-
f'The feature_name parameter is deprecated. Use "feature_names".'
|
167
|
-
)
|
168
|
-
self._feature_names = [self._feature_name_deprecated]
|
169
|
-
|
170
|
-
def _inject_deprecated_output_name(self):
|
171
|
-
if len(self._feature_names) == 1 and self._output_name_deprecated:
|
172
|
-
if len(self._rename_outputs) > 0:
|
173
|
-
raise ValueError(
|
174
|
-
"Use either output_name or rename_outputs parameter, but not both."
|
175
|
-
)
|
176
|
-
_logger.warning(
|
177
|
-
f'The output_name parameter is deprecated. Use "rename_outputs".'
|
178
|
-
)
|
179
|
-
self._rename_outputs[self._feature_names[0]] = self._output_name_deprecated
|