Skip to content

Commit

Permalink
feat: Add more __repr__ methods (feast-dev#4676)
Browse files Browse the repository at this point in the history
  • Loading branch information
emgeee authored Oct 24, 2024
1 parent 5291289 commit e726c09
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
14 changes: 14 additions & 0 deletions sdk/python/feast/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ def __init__(
self.created_timestamp = None
self.last_updated_timestamp = None

def __repr__(self):
return (
f"Entity(\n"
f" name={self.name!r},\n"
f" value_type={self.value_type!r},\n"
f" join_key={self.join_key!r},\n"
f" description={self.description!r},\n"
f" tags={self.tags!r},\n"
f" owner={self.owner!r},\n"
f" created_timestamp={self.created_timestamp!r},\n"
f" last_updated_timestamp={self.last_updated_timestamp!r}\n"
f")"
)

def __hash__(self) -> int:
return hash((self.name, self.join_key))

Expand Down
12 changes: 9 additions & 3 deletions sdk/python/feast/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ def __lt__(self, other):
return self.name < other.name

def __repr__(self):
# return string representation of the reference
return f"{self.name}-{self.dtype}"
return (
f"Feature(\n"
f" name={self._name!r},\n"
f" dtype={self._dtype!r},\n"
f" description={self._description!r},\n"
f" labels={self._labels!r}\n"
f")"
)

def __str__(self):
# readable string of the reference
return f"Feature<{self.__repr__()}>"
return f"Feature<{self.name}: {self.dtype}>"

@property
def name(self):
Expand Down
10 changes: 10 additions & 0 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ def version(self) -> str:
"""Returns the version of the current Feast SDK/CLI."""
return get_version()

def __repr__(self) -> str:
return (
f"FeatureStore(\n"
f" repo_path={self.repo_path!r},\n"
f" config={self.config!r},\n"
f" registry={self._registry!r},\n"
f" provider={self._provider!r}\n"
f")"
)

@property
def registry(self) -> BaseRegistry:
"""Gets the registry of this feature store."""
Expand Down
9 changes: 8 additions & 1 deletion sdk/python/feast/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ def __lt__(self, other):
return self.name < other.name

def __repr__(self):
return f"Field(name='{self.name}', dtype={self.dtype}, description='{self.description}' tags={self.tags})"
return (
f"Field(\n"
f" name={self.name!r},\n"
f" dtype={self.dtype!r},\n"
f" description={self.description!r},\n"
f" tags={self.tags!r}\n"
f")"
)

def __str__(self):
return f"Field(name={self.name}, dtype={self.dtype}, tags={self.tags})"
Expand Down

0 comments on commit e726c09

Please sign in to comment.