|
17 | 17 |
|
18 | 18 | import pandas as pd |
19 | 19 | import pyarrow as pa |
| 20 | +import yaml |
20 | 21 | from google.protobuf import json_format |
21 | 22 | from google.protobuf.duration_pb2 import Duration |
22 | | -from google.protobuf.json_format import MessageToJson |
| 23 | +from google.protobuf.json_format import MessageToDict, MessageToJson |
23 | 24 | from google.protobuf.message import Message |
24 | 25 | from pandas.api.types import is_datetime64_ns_dtype |
25 | 26 | from pyarrow.lib import TimestampType |
@@ -79,12 +80,18 @@ def __eq__(self, other): |
79 | 80 | if key not in other.fields.keys() or self.fields[key] != other.fields[key]: |
80 | 81 | return False |
81 | 82 |
|
| 83 | + if self.fields[key] != other.fields[key]: |
| 84 | + return False |
| 85 | + |
82 | 86 | if ( |
83 | 87 | self.name != other.name |
84 | 88 | or self.project != other.project |
85 | 89 | or self.max_age != other.max_age |
86 | 90 | ): |
87 | 91 | return False |
| 92 | + |
| 93 | + if self.source != other.source: |
| 94 | + return False |
88 | 95 | return True |
89 | 96 |
|
90 | 97 | def __str__(self): |
@@ -783,13 +790,18 @@ def from_proto(cls, feature_set_proto: FeatureSetProto): |
783 | 790 | entities=[ |
784 | 791 | Entity.from_proto(entity) for entity in feature_set_proto.spec.entities |
785 | 792 | ], |
786 | | - max_age=feature_set_proto.spec.max_age, |
| 793 | + max_age=( |
| 794 | + None |
| 795 | + if feature_set_proto.spec.max_age.seconds == 0 |
| 796 | + and feature_set_proto.spec.max_age.nanos == 0 |
| 797 | + else feature_set_proto.spec.max_age |
| 798 | + ), |
787 | 799 | source=( |
788 | 800 | None |
789 | 801 | if feature_set_proto.spec.source.type == 0 |
790 | 802 | else Source.from_proto(feature_set_proto.spec.source) |
791 | 803 | ), |
792 | | - project=feature_set_proto.spec.project |
| 804 | + project=None |
793 | 805 | if len(feature_set_proto.spec.project) == 0 |
794 | 806 | else feature_set_proto.spec.project, |
795 | 807 | ) |
@@ -828,6 +840,29 @@ def to_proto(self) -> FeatureSetProto: |
828 | 840 |
|
829 | 841 | return FeatureSetProto(spec=spec, meta=meta) |
830 | 842 |
|
| 843 | + def to_dict(self) -> Dict: |
| 844 | + """ |
| 845 | + Converts feature set to dict |
| 846 | +
|
| 847 | + :return: Dictionary object representation of feature set |
| 848 | + """ |
| 849 | + feature_set_dict = MessageToDict(self.to_proto()) |
| 850 | + |
| 851 | + # Remove meta when empty for more readable exports |
| 852 | + if feature_set_dict["meta"] == {}: |
| 853 | + del feature_set_dict["meta"] |
| 854 | + |
| 855 | + return feature_set_dict |
| 856 | + |
| 857 | + def to_yaml(self): |
| 858 | + """ |
| 859 | + Converts a feature set to a YAML string. |
| 860 | +
|
| 861 | + :return: Feature set string returned in YAML format |
| 862 | + """ |
| 863 | + feature_set_dict = self.to_dict() |
| 864 | + return yaml.dump(feature_set_dict, allow_unicode=True, sort_keys=False) |
| 865 | + |
831 | 866 |
|
832 | 867 | class FeatureSetRef: |
833 | 868 | """ |
|
0 commit comments