Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add __hash__
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 committed Apr 6, 2022
commit c59291b7d4ca7ff4fc5f73d28c42bb784c8211a1
14 changes: 14 additions & 0 deletions sdk/python/feast/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from feast.feature import Feature
from feast.protos.feast.core.Feature_pb2 import FeatureSpecV2 as FieldProto
from feast.types import FeastType, from_value_type

Expand Down Expand Up @@ -45,6 +46,9 @@ def __eq__(self, other):
if self.name != other.name or self.dtype != other.dtype:
return False
return True

def __hash__(self):
return hash((id(self), self.name))

def __lt__(self, other):
return self.name < other.name
Expand All @@ -68,3 +72,13 @@ def from_proto(cls, field_proto: FieldProto):
field_proto: FieldProto protobuf object
"""
return cls(name=field_proto.name, dtype=from_value_type(field_proto.value_type))

@classmethod
def from_feature(cls, feature: Feature):
"""
Creates a Field object from a Feature object.

Args:
feature: Feature object to convert.
"""
return cls(name=feature.name, dtype=from_value_type(feature.dtype.value))