FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
feast/sdk/python/feast/feature.py at master · npow/feast · GitHub
npow
/
feast
Public
forked from
feast-dev/feast
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
feast
/
sdk
/
python
/
feast
/
feature.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (93 loc) · 3.17 KB
Breadcrumbs
feast
/
sdk
/
python
/
feast
/
feature.py
Copy path
File metadata and controls
112 lines (93 loc) · 3.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2020 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
typing
import
Dict
,
Optional
from
feast
.
protos
.
feast
.
core
.
Feature_pb2
import
FeatureSpecV2
as
FeatureSpecProto
from
feast
.
protos
.
feast
.
types
import
Value_pb2
as
ValueTypeProto
from
feast
.
value_type
import
ValueType
class
Feature
:
"""
A Feature represents a class of serveable feature.
Args:
name: Name of the feature.
dtype: The type of the feature, such as string or float.
labels (optional): User-defined metadata in dictionary form.
"""
def
__init__
(
self
,
name
:
str
,
dtype
:
ValueType
,
labels
:
Optional
[
Dict
[
str
,
str
]]
=
None
,
):
"""Creates a Feature object."""
self
.
_name
=
name
if
not
isinstance
(
dtype
,
ValueType
):
raise
ValueError
(
"dtype is not a valid ValueType"
)
if
dtype
is
ValueType
.
UNKNOWN
:
raise
ValueError
(
f"dtype cannot be
{
dtype
}
"
)
self
.
_dtype
=
dtype
if
labels
is
None
:
self
.
_labels
=
dict
()
else
:
self
.
_labels
=
labels
def
__eq__
(
self
,
other
):
if
self
.
name
!=
other
.
name
or
self
.
dtype
!=
other
.
dtype
:
return
False
return
True
def
__lt__
(
self
,
other
):
return
self
.
name
<
other
.
name
def
__repr__
(
self
):
# return string representation of the reference
return
f"
{
self
.
name
}
-
{
self
.
dtype
}
"
def
__str__
(
self
):
# readable string of the reference
return
f"Feature<
{
self
.
__repr__
()
}
>"
@
property
def
name
(
self
):
"""
Gets the name of this feature.
"""
return
self
.
_name
@
property
def
dtype
(
self
)
->
ValueType
:
"""
Gets the data type of this feature.
"""
return
self
.
_dtype
@
property
def
labels
(
self
)
->
Dict
[
str
,
str
]:
"""
Gets the labels of this feature.
"""
return
self
.
_labels
def
to_proto
(
self
)
->
FeatureSpecProto
:
"""
Converts Feature object to its Protocol Buffer representation.
Returns:
A FeatureSpecProto protobuf.
"""
value_type
=
ValueTypeProto
.
ValueType
.
Enum
.
Value
(
self
.
dtype
.
name
)
return
FeatureSpecProto
(
name
=
self
.
name
,
value_type
=
value_type
,
labels
=
self
.
labels
,
)
@
classmethod
def
from_proto
(
cls
,
feature_proto
:
FeatureSpecProto
):
"""
Args:
feature_proto: FeatureSpecV2 protobuf object
Returns:
Feature object
"""
feature
=
cls
(
name
=
feature_proto
.
name
,
dtype
=
ValueType
(
feature_proto
.
value_type
),
labels
=
dict
(
feature_proto
.
labels
),
)
return
feature
Back
|
FazBrowse Home
|
New Git URL