Skip to content

Commit

Permalink
fix: more useful repr for stack (#449)
Browse files Browse the repository at this point in the history
* fix: nicer stack repr

Signed-off-by: Henry Schreiner <[email protected]>

* fix: avoid listing label when unset

Signed-off-by: Henry Schreiner <[email protected]>

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Sep 20, 2022
1 parent 89dce29 commit b2856b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## Version 2.6.2

* Nicer stacks repr
[#449](https://github.com/scikit-hep/hist/pull/449)
* Backport `storage_type` if boost-histogram < 1.3.2
[#447](https://github.com/scikit-hep/hist/pull/447)
* Allow overwriting labels for plot/overlay
[#414](https://github.com/scikit-hep/hist/pull/414)
* Use Hatching to build the package
[#418](https://github.com/scikit-hep/hist/pull/418)
* Support git archival version numbers
[#441](https://github.com/scikit-hep/hist/pull/441)


## Version 2.6.1

* Fall back on normal repr when histogram is too large
Expand Down
2 changes: 1 addition & 1 deletion src/hist/axis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _repr_args_(self: AxisProtocol) -> list[str]:

if self.name:
ret.append(f"name={self.name!r}")
if self.label:
if self.label and self.label != self.name:
ret.append(f"label={self.label!r}")

return ret
Expand Down
5 changes: 3 additions & 2 deletions src/hist/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def __len__(self) -> int:
return len(self._stack)

def __repr__(self) -> str:
str_stack = ", ".join(repr(h) for h in self)
return f"{self.__class__.__name__}({str_stack})"
names = ", ".join(repr(getattr(h, "name", f"H{i}")) for i, h in enumerate(self))
h = repr(self[0]) if len(self) else "Empty stack"
return f"{self.__class__.__name__}<({names}) of {h}>"

def __eq__(self, other: Any) -> bool:
if not isinstance(other, Stack):
Expand Down

0 comments on commit b2856b6

Please sign in to comment.