Skip to content

Commit

Permalink
Merge pull request #45 from scipp/fix-html-repr
Browse files Browse the repository at this point in the history
Use str repr for param table html repr when `__name__` does not exist
  • Loading branch information
nvaytet authored Aug 31, 2023
2 parents 623ab45 + 344a172 commit dec803d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/sciline/param_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ def __len__(self) -> int:
return self._columns.__len__()

def __repr__(self) -> str:
return f"ParamTable(row_dim={self.row_dim}, columns={self._columns})"
return f"ParamTable(row_dim={self.row_dim.__name__}, columns={self._columns})"

def _repr_html_(self) -> str:
return (
f"<table><tr><th>{self.row_dim.__name__}</th>"
+ "".join(f"<th>{k.__name__}</th>" for k in self._columns.keys())
+ "".join(
f"<th>{getattr(k, '__name__', str(k).split('.')[-1])}</th>"
for k in self._columns.keys()
)
+ "</tr>"
+ "".join(
f"<tr><td>{idx}</td>" + "".join(f"<td>{v}</td>" for v in row) + "</tr>"
Expand Down
2 changes: 1 addition & 1 deletion src/sciline/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __getitem__(self, key: Key) -> Value:
return self._map[key]

def __repr__(self) -> str:
return f"Series(row_dim={self.row_dim}, {self._map})"
return f"Series(row_dim={self.row_dim.__name__}, {self._map})"

def _repr_html_(self) -> str:
return (
Expand Down

0 comments on commit dec803d

Please sign in to comment.