Skip to content

Commit

Permalink
Add: Index.__repr_pretty__
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Mar 30, 2024
1 parent a3287f1 commit 7087138
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions python/usearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,12 +1234,10 @@ def __repr__(self) -> str:
self.hardware_acceleration,
)

def _repr_pretty_(self, printer, cycle) -> str:
def __repr_pretty__(self) -> str:
if not hasattr(self, "_compiled"):
return "usearch.Index(failed)"
level_stats = [
f"--- {i}. {self.level_stats(i).nodes:,} nodes" for i in range(self.nlevels)
]
level_stats = [f"--- {i}. {self.level_stats(i).nodes:,} nodes" for i in range(self.nlevels)]
lines = "\n".join(
[
"usearch.Index",
Expand All @@ -1263,7 +1261,10 @@ def _repr_pretty_(self, printer, cycle) -> str:
*level_stats,
]
)
printer.text(lines)
return lines

def _repr_pretty_(self, printer, cycle):
printer.text(self.__repr_pretty__())


class Indexes:
Expand Down

0 comments on commit 7087138

Please sign in to comment.