Skip to content

Commit

Permalink
Merge pull request #70 from nschloe/div-by-zero
Browse files Browse the repository at this point in the history
Div by zero
  • Loading branch information
nschloe authored Jul 8, 2021
2 parents 4d579a5 + d0deeed commit aba99ee
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v2
with:
python-version: "3.x"
- uses: actions/checkout@v2
- name: Lint with flake8
run: |
pip install flake8
flake8 .
- name: Lint with black
run: |
pip install black
black --check .
- name: Check out repo
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Run pre-commit
uses: pre-commit/action@v2.0.3

build:
runs-on: ubuntu-latest
Expand Down
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.9.1
hooks:
- id: isort

- repo: https://github.com/python/black
rev: 21.6b0
hooks:
- id: black
language_version: python3

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = termplotlib
version = 0.3.7
version = 0.3.8
author = Nico Schlömer
author_email = nico.schloemer@gmail.com
description = Python plotting for the command line
Expand Down
5 changes: 4 additions & 1 deletion src/termplotlib/barh.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def _get_matrix_of_eighths(counts, max_size: int, bar_width: int) -> List[List[i
max_count = max(counts)

# translate to eighths of a textbox
eighths = [int(round(count / max_count * max_size * 8)) for count in counts]
if max_count == 0:
eighths = [0 for _ in counts]
else:
eighths = [int(round(count / max_count * max_size * 8)) for count in counts]

# prepare matrix
matrix = [[0] * max_size for _ in range(len(eighths))]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_barh.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ def test_barh_floats():
)


def test_div_by_zero():
fig = tpl.figure()
fig.barh([0, 0], ["Eggs", "Dogs"])
string = fig.get_string()
print(string)
assert (
string
== """\
Eggs [0]
Dogs [0]\
"""
)


if __name__ == "__main__":
# test_horizontal_ascii()
# test_barh()
Expand Down

0 comments on commit aba99ee

Please sign in to comment.