Skip to content

Commit

Permalink
Add __hash__
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 committed Apr 6, 2022
1 parent 0104782 commit c59291b
Showing 1 changed file with 14 additions and 0 deletions.
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))

0 comments on commit c59291b

Please sign in to comment.