Iteround: Sum-safe Rounding for Iterables
.. image:: https://travis-ci.org/cgdeboer/iteround.svg?branch=master :target: https://travis-ci.org/cgdeboer/iteround
.. 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).
.. image:: https://raw.githubusercontent.com/cgdeboer/iteround/master/docs/iteround.png
Example Code:
.. code-block:: python
>>> import iteround
>>> data = {'foo': 60.19012964572332,
'bar': 15.428802458406679,
'baz': 24.381067895870007}
>>> sum(data.values())
100.0
>>> rounded = iteround.saferound(data, 0)
>>> rounded
{'foo': 60.0,
'bar': 16.0,
'baz': 24.0}
>>> sum(rounded.values())
100.0
How It Works
Iteround provides a single method, called :code:saferound that takes the
following inputs:
iterable (list, dict, set, numpy.array, generator): list(y) of numbers If a dict is passed in, the values must be all floats.
places (int): Places for rounding. Number of places each item in the set should be rounded to.
topline (float, optional): Topline to match Useful in places where we want the total sum to match a different topline than the sum of iterable. This can useful in cases where original values are altered before passing into the saferound method, but the original sum needs to be maintained.
strategy (str, optional): The strategy used to clean up rounding errors 'difference', 'largest', 'smallest'. Defaults to 'difference'
'difference' seeks to minimize the sum of the array of the
differences between the original value and the rounded value of
each item in the iterable. It will adjust the items with the
largest difference to preserve the sum. This is the default.
'largest' for any post rounding adjustments, sort the array by
the largest values to smallest and adjust those first.
'smallest' for any post rounding adjustments, sort the array by
the smallest values to largest, adjust the smaller ones first.
Strategy strings are available as:
:code:`iteround.DIFFERENCE`
:code:`iteround.LARGEST`
:code:`iteround.SMALLEST`
If 'dict' or 'tuple' are passed, result will be dict or tuple. All other iterables (range, map, np.array, etc) will return list.
Feature Support
Iteround definitely supports at least these iterables.
listtupledictOrderedDict
Iteround officially supports Python 2.7 & 3.4–3.6.
Installation
To install Iteround, use pipenv <http://pipenv.org/>_ (or pip, of course):
.. code-block:: bash
$ pipenv install iteround
Documentation
Documentation beyond this readme will be available soon.
How to Contribute
#. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
#. Fork the repository_ on GitHub to start making your changes to the master branch (or branch off of it).
#. Write a test which shows that the bug was fixed or that the feature works as expected.
#. Send a pull request. Make sure to add yourself to AUTHORS_.
.. _the repository: https://github.com/cgdeboer/iteround
.. _AUTHORS: https://github.com/cgdeboer/iteround/blob/master/AUTHORS.rst
Metadata
Release files for iteround 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iteround-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for iteround-1.0.4-py3-none-any.whl |
Release files / iteround-1.0.4-py3-none-any.whl
| Download URL | iteround-1.0.4-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17947dd5479177e6fb186b0a3d5d594b55eedea14dc722c6da7e84bbed45f5b2
|
|
BLAKE2b-256 checksum How to use checksums |
26c768d920f791cd99919d82dd6db9fc0aca3790dc8d67c69b559a447ca2a914
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.5
|
Security for iteround 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.