Skip to content

Commit

Permalink
update topline hang for empty iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin DeBoer committed Apr 20, 2022
1 parent 40ca2cf commit 98abc18
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Iteround: Sum-safe Rounding for Iterables
.. image:: https://img.shields.io/pypi/v/iteround.svg
:target: https://pypi.org/project/iteround/

.. image:: https://img.shields.io/conda/vn/conda-forge/iteround.svg
:target: https://anaconda.org/conda-forge/iteround

Iteround is an organic (standard library) sum-safe rounding library for Python
iterables (lists, tuples, dicts).

Expand Down
2 changes: 1 addition & 1 deletion iteround/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def saferound(iterable, places, strategy=DIFFERENCE, rounder=round, topline=None
local_sum = _sumnum(local, places, rounder)

# adjust values to adhere to original sum
while local_sum != orig_sum:
while local and local_sum != orig_sum:
diff = rounder(orig_sum - local_sum, places)
if diff < 0.:
increment = -1 * _mininc(places)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_saferound.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def test_topline_sum(self):
self.assertEqual(sum(iteround.saferound(self.in_list, 0, topline=29)), 29)
self.assertEqual(sum(iteround.saferound(self.in_list, 0, topline=30)), 30)

def test_empty_returns_empty(self):
out = []
topline = 1
actual_out = iteround.saferound([], 0, topline=topline)
self.assertListEqual(actual_out, out)


if __name__ == '__main__':
unittest.main()

0 comments on commit 98abc18

Please sign in to comment.