Skip to content

Commit

Permalink
Render histograms without spaces between bins
Browse files Browse the repository at this point in the history
This makes it easier to read the histogram.

Signed-off-by: Matt Wozniski <[email protected]>
  • Loading branch information
godlygeek authored and pablogsal committed Mar 7, 2024
1 parent ef5514c commit 26b5ac6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pytest_memray/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def cli_hist(data: Iterable[float], bins: int, *, log_scale: bool = True) -> str
high = max(data)
data_bins = histogram(data, low=low, high=high, bins=bins)
bar_indexes = (int(elem * (len(bars) - 1) / max(data_bins)) for elem in data_bins)
result = " ".join(bars[bar_index] for bar_index in bar_indexes)
result = "".join(bars[bar_index] for bar_index in bar_indexes)
return result


Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_histogram_with_zero_byte_allocations():
histogram = cli_hist(allocations, bins=5)

# THEN
assert histogram == "▄ ▄ █ ▄"
assert histogram == "▄ ▄█▄"


def test_histogram_with_only_zero_byte_allocations():
Expand All @@ -145,4 +145,4 @@ def test_histogram_with_only_zero_byte_allocations():
histogram = cli_hist(allocations, bins=5)

# THEN
assert histogram == "█ "
assert histogram == "█ "

0 comments on commit 26b5ac6

Please sign in to comment.