Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more useful repr for stack #449

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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