-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for other numerical types at the registry level
Until this commit, `int` and `float` were special types in Pint (just as they are in Python). Numbers were parsed from strings as int/float from the definition files and from user provided strings; and exponents of units were also stored as int/float. This commit change this by adding a new argument (`non_int_type`) to classes and methods. It indicates how numeric values will be parsed and defaulted. Any numerical class can be used such as `float` (default), Decimal, Fraction. This argument will be found in the following places 1. UnitRegistry: used for parsing the definition files and any value provided as a string. 2. UnitsContainer: used to compare equality with strings, multiply and divide by strings (which is equivalent to parse the string) 3. All methods OUTSIDE the UnitRegistry/Quantity that can parse strings have a `non_int_type` argument. (e.g. Definition.from_string) Tests have been added for by duplicating most cases in `test_quantity.py`. (Some tests have been deleted such as those dealing with numpy.) The new file `test_non_int.py` run the tests for `Decimal`, `Fraction` and `float` (which is redundant but is kept as a crosscheck for the implementation of this testsuite) BREAKING CHANGE: `use_decimal` is deprecated. Use `non_int_type` keyword argument when instantiating the registry. >>> from decimal import Decimal >>> ureg = UnitRegistry(non_int_type=Decimal)
- Loading branch information
Showing
9 changed files
with
1,284 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.