Skip to content

Commit b2856b6

Browse files
authored
fix: more useful repr for stack (#449)
* fix: nicer stack repr Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix: avoid listing label when unset Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 89dce29 commit b2856b6

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## Version 2.6.2
4+
5+
* Nicer stacks repr
6+
[#449](https://github.com/scikit-hep/hist/pull/449)
7+
* Backport `storage_type` if boost-histogram < 1.3.2
8+
[#447](https://github.com/scikit-hep/hist/pull/447)
9+
* Allow overwriting labels for plot/overlay
10+
[#414](https://github.com/scikit-hep/hist/pull/414)
11+
* Use Hatching to build the package
12+
[#418](https://github.com/scikit-hep/hist/pull/418)
13+
* Support git archival version numbers
14+
[#441](https://github.com/scikit-hep/hist/pull/441)
15+
16+
317
## Version 2.6.1
418

519
* Fall back on normal repr when histogram is too large

src/hist/axis/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _repr_args_(self: AxisProtocol) -> list[str]:
8282

8383
if self.name:
8484
ret.append(f"name={self.name!r}")
85-
if self.label:
85+
if self.label and self.label != self.name:
8686
ret.append(f"label={self.label!r}")
8787

8888
return ret

src/hist/stack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ def __len__(self) -> int:
111111
return len(self._stack)
112112

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

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

0 commit comments

Comments
 (0)