Super-fast and clean conversions to numbers.
Project description
Super-fast and clean conversions to numbers.
Source Code: https://github.com/SethMMorton/fastnumbers
Downloads: https://pypi.org/project/fastnumbers/
Documentation: http://fastnumbers.readthedocs.io/
fastnumbers is a module with the following three objectives:
Provide drop-in replacements for the Python built-in int and float that on average are up to 2x faster. These functions should behave identically to the Python built-ins except for a few specific corner-cases as mentioned in the API documentation.
Provide a set of convenience functions that wrap the above int and float replacements and provides easy, concise, powerful, fast and flexible error handling.
Provide a set of functions that can be used to rapidly identify if an input could be converted to int or float.
Examples
The below examples showcase the fast_float function, which is a fast conversion function with error-handling. Please see the API Documentation for other functions that are available from fastnumbers.
>>> from fastnumbers import fast_float, float as fnfloat
>>> # Convert string to a float
>>> fast_float('56.07')
56.07
>>> # Unconvertable string returned as-is by default
>>> fast_float('bad input')
'bad input'
>>> # Unconvertable strings can trigger a default value
>>> fast_float('bad input', default=0)
0
>>> # 'default' is also the first optional positional arg
>>> fast_float('bad input', 0)
0
>>> # Integers are converted to floats
>>> fast_float(54)
54.0
>>> # One can ask inf or nan to be substituted with another value
>>> fast_float('nan')
nan
>>> fast_float('nan', nan=0.0)
0.0
>>> fast_float(float('nan'), nan=0.0)
0.0
>>> fast_float('56.07', nan=0.0)
56.07
>>> # The default built-in float behavior can be triggered with
>>> # "raise_on_invalid" set to True.
>>> fast_float('bad input', raise_on_invalid=True) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: invalid literal for float(): bad input
>>> # A key function can be used to return an alternate value for invalid input
>>> fast_float('bad input', key=len)
9
>>> fast_float(54, key=len)
54.0
>>> # Single unicode characters can be converted.
>>> fast_float(u'\u2164') # Roman numeral 5 (V)
5.0
>>> fast_float(u'\u2466') # 7 enclosed in a circle
7.0
NOTE: If you need locale-dependent conversions, supply the fastnumbers function of your choice to locale.atof.
import locale
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
print(atof('468,5', func=fast_float)) # Prints 468.5
Timing
Just how much faster is fastnumbers than a pure python implementation? Please see the following Jupyter notebooks for timing information on various Python versions.
History
These are the last three entries of the changelog. See the package documentation for the complete changelog.
11-11-2017 v. 2.0.2
Updated docstrings.
Improved timing documentation.
Added testing for Python 3.7.
04-30-2017 v. 2.0.1
Fixed bug in decimal digit limit on GCC.
04-30-2017 v. 2.0.0
Dropped support for Python 2.6.
Added support for Python 3.6 underscores.
Added drop-in replacements for the built-in int() and float() functions.
Incorporated unit tests from Python’s testing library to ensure that any input that Python can handle will also be handled the same way by fastnumbers.
Added Appveyor testing to ensure no surprises on Windows.
Revamped documentation.
Refactored internal mechanism for assessing overflow to be faster in the most common cases.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file fastnumbers-2.0.2.tar.gz
.
File metadata
- Download URL: fastnumbers-2.0.2.tar.gz
- Upload date:
- Size: 348.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb643edbad37dba9fb14c51fafff573e5ff81fcb903628c2d6c98ed4b88f34f |
|
MD5 | 2e2e1d21ef0aaffdb24945c9c3f5416d |
|
BLAKE2b-256 | c183e260ec61f1a1c7c8e5e4893d550a7bfbc1e8cef7ea8f7b9865f48c9bdbb1 |
File details
Details for the file fastnumbers-2.0.2.win-amd64-py3.6.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win-amd64-py3.6.exe
- Upload date:
- Size: 617.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ea4137c887edff0b93c8e55d22508caa771d64df16cfe723a48663b03f8163 |
|
MD5 | 99c3dd13ffdc5245b122a0a0ef6268b9 |
|
BLAKE2b-256 | a5277960fddd4d98b742ca9dca04b8983015d7c73275216e0309db24cd0e8f51 |
File details
Details for the file fastnumbers-2.0.2.win-amd64-py3.5.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win-amd64-py3.5.exe
- Upload date:
- Size: 617.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b8d319c13df7d0f6c89fd2d57f2c38060bc4392f842081bafaf4beefa2c95b6 |
|
MD5 | 6c0982c7ffa4521db46b086eab7e7476 |
|
BLAKE2b-256 | 85ac0605ba0fa8a9a94806a7a7042ad838da38725a00a29cbf1a239a6e57b508 |
File details
Details for the file fastnumbers-2.0.2.win-amd64-py3.4.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win-amd64-py3.4.exe
- Upload date:
- Size: 249.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae916d964011e7241ff4f80b52debb2a6cc67b88581dba53801adde7a13d135 |
|
MD5 | 0a8e59d46e2c005d1a4f0bfb03f1240e |
|
BLAKE2b-256 | 15d4f703426e5df628e0ac8b06ef869bf035f35243854fc17944ae6696e7ddd2 |
File details
Details for the file fastnumbers-2.0.2.win-amd64-py3.3.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win-amd64-py3.3.exe
- Upload date:
- Size: 249.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8994ae23c5f663e81fdf08631767a29dd3b9246bfdffdfd7a9811e826d558122 |
|
MD5 | 2f758061867ea5de879b07f52a8bfbc5 |
|
BLAKE2b-256 | 793d4628ecdc5e9cced024463d7253f8b0d35417d71903cc59762439de4141ad |
File details
Details for the file fastnumbers-2.0.2.win-amd64-py2.7.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win-amd64-py2.7.exe
- Upload date:
- Size: 250.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed8fea4da2e7eea9eb6305fe379a7ec30460d4db9bc6e2721bc79d14f9f35d40 |
|
MD5 | 36cd4e4f6b1d7f4a406286314f17c462 |
|
BLAKE2b-256 | ed22e1f20be80c5ea65e221e29d02b2b371003b771ead9131b48679082c864d5 |
File details
Details for the file fastnumbers-2.0.2.win32-py3.6.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win32-py3.6.exe
- Upload date:
- Size: 486.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60cd6e64af8a08ce469abf8c144f2006046d20945deee3b9bd8bc9abbcf94b10 |
|
MD5 | 864ff776c5553faad0f636c30592449d |
|
BLAKE2b-256 | 1fe1b4a7496bd61e9b633d9a5d5289354acf21b3a3d1be37774b922baf253bf7 |
File details
Details for the file fastnumbers-2.0.2.win32-py3.5.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win32-py3.5.exe
- Upload date:
- Size: 486.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ad1f702e846345d8a4622c0d45e45ab4eb6975760addc4e5f294b64d5d5fce1 |
|
MD5 | 088118de89cde24cb1bf91577bf3ff3e |
|
BLAKE2b-256 | 1737828702fd4392071b761210d905a81a4cee34ca0815e611535b4b3ffb9561 |
File details
Details for the file fastnumbers-2.0.2.win32-py3.4.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win32-py3.4.exe
- Upload date:
- Size: 217.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53ba0e6bc231dab286661ced66195db4c942b52acc5e937f3da3b14e791c2c2e |
|
MD5 | d692d6ff641e754c50b74a61be4b0efe |
|
BLAKE2b-256 | 82cbcdeb1d77cfac95bfb17e20058566cd2e95fb58d1a511b931ddd8997148d7 |
File details
Details for the file fastnumbers-2.0.2.win32-py3.3.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win32-py3.3.exe
- Upload date:
- Size: 217.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 702e54ea83f69000b2a96cab98d830268c807fc51ef75b4fecac9866cbae0005 |
|
MD5 | 443a88fd9d7f78a09fce3b4105c9b95a |
|
BLAKE2b-256 | 7cb61ebd374576f4c2231e727852e07309b16ed8dcb4c4dc2ed1c8c76b31ab80 |
File details
Details for the file fastnumbers-2.0.2.win32-py2.7.exe
.
File metadata
- Download URL: fastnumbers-2.0.2.win32-py2.7.exe
- Upload date:
- Size: 223.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45b2010e0ae8009e50248d999c897cbe546997402fc31cdb9e8ed25b47631c1c |
|
MD5 | 868ca9b98dbaaea6ea3193b4975ec3a6 |
|
BLAKE2b-256 | 59275879498ab8f80ce81a8d94fb9fce3cf84a2109e660005b6b65b4de197301 |
File details
Details for the file fastnumbers-2.0.2-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0eb3dc2c7148166d7b66d4e5addd15781a08f0397951d79b2a0a0da82cab83 |
|
MD5 | 3b0cb864cb184ee088e2d3b2c6bff93d |
|
BLAKE2b-256 | fc801717a5b075dec426a06d1f2afd0f7f506cb370d99d97a8cb3c16b7b04d20 |
File details
Details for the file fastnumbers-2.0.2-cp36-cp36m-win32.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp36-cp36m-win32.whl
- Upload date:
- Size: 24.8 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d710cfc137fb24575d9c4407b68ee9877bbd4180655829e76108e837141f5fb |
|
MD5 | 6aa6601cc0a67f2fe4f1d40d34a635b0 |
|
BLAKE2b-256 | a11b28650a47805f2b21d0b278088286733742deb1303d8f87b3bb15b97ca415 |
File details
Details for the file fastnumbers-2.0.2-cp36-cp36m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp36-cp36m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 23.4 kB
- Tags: CPython 3.6m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20167f619dc8eeb807576d4faba0100b417dad72add92e9e31c6ef28ea58fde3 |
|
MD5 | 322d5e1bab2b8229a4023d58a6ef8e25 |
|
BLAKE2b-256 | f31dcca87af6e4216f8f5796baa3d0a95a62fe819dd32d2313f8fd81be280983 |
File details
Details for the file fastnumbers-2.0.2-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 25.9 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3e7d8b1e796f1256a70853bd7b2f7151baadcddf9838390daee0d575c5be49f |
|
MD5 | cc1897f1320af0a2b063baa4e1c0797e |
|
BLAKE2b-256 | 1d92ba76853bfbc925707c74884817b7c31bb3b706d4b4ce2d99b11aa859eb2e |
File details
Details for the file fastnumbers-2.0.2-cp35-cp35m-win32.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp35-cp35m-win32.whl
- Upload date:
- Size: 24.6 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 083ab5826a81767d345b8cc98cc2237ae9246a3d54cc04909591e36cc3b8075a |
|
MD5 | a62b486960fe7460427752e6f95312d3 |
|
BLAKE2b-256 | 2ef7aed25f7c2207d2a9a529588ecadade45d4cbd951709953f18088d3d353e2 |
File details
Details for the file fastnumbers-2.0.2-cp35-cp35m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp35-cp35m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 23.1 kB
- Tags: CPython 3.5m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42bc9bc0ecbd9ef797654a23e68bc0fc0c391f1146c1212e8653ff329bb9a5bf |
|
MD5 | dc232f747d31b7ce79c3f63ac4280a54 |
|
BLAKE2b-256 | 3c73462b47d4bfac7a10a00114a6c993de2fc4f5454c5f4e0ba06ad4183cb3fc |
File details
Details for the file fastnumbers-2.0.2-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 23.1 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6aa9c2057211e4a8c6c6f083f2fc68b54912a62eca1a7038055fe6aa957affe |
|
MD5 | 1c5362b20897828fa2aebbedfb64f3c2 |
|
BLAKE2b-256 | 0c942f73abb7463d8c2c0e5c948406ca698db47f7d6d8e85f41358e19c3b33fc |
File details
Details for the file fastnumbers-2.0.2-cp34-cp34m-win32.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp34-cp34m-win32.whl
- Upload date:
- Size: 23.0 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a59e707aa1e3f83a8479e4a07942fc6b41186f7456b6a215d1e9462d248e042b |
|
MD5 | 863dcf70aab59966ca937bcca8c8946d |
|
BLAKE2b-256 | 639166f3d4d9c886bfbf22e09b7761592cc2ce52b8b8798787da784dea67753c |
File details
Details for the file fastnumbers-2.0.2-cp34-cp34m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp34-cp34m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 23.0 kB
- Tags: CPython 3.4m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 350d5d544ea660d13f73dd43f435a8ac5b62cdbc064a36e27e974bac4f69647f |
|
MD5 | 00c87432b58e1e1e87c4f1fa6c7d453a |
|
BLAKE2b-256 | 438fa764cf6977f2102591723676083573ad71961a869098d85ef2e267dffed9 |
File details
Details for the file fastnumbers-2.0.2-cp33-cp33m-win_amd64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp33-cp33m-win_amd64.whl
- Upload date:
- Size: 23.1 kB
- Tags: CPython 3.3m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e6d06948bfbe9973a2d1333b202e9cbb5a35f5d9be62a1201b9092b30907208 |
|
MD5 | d0a1399ac548703819b0fbaf8325cc9a |
|
BLAKE2b-256 | c05c3172df43979036a8ae972b7244dcc1e10b16f374c0fea35511fc48b6f5cc |
File details
Details for the file fastnumbers-2.0.2-cp33-cp33m-win32.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp33-cp33m-win32.whl
- Upload date:
- Size: 23.0 kB
- Tags: CPython 3.3m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa51fa648ab3d0ef110b1cf9633312a7926699249934e0cfb3a50f98923bc132 |
|
MD5 | b889b238a8b1494971395a425f050d0f |
|
BLAKE2b-256 | 0b3187c78c23b6e3dc90be63a454917769f88c0072f44b598efe64a89d9a253f |
File details
Details for the file fastnumbers-2.0.2-cp33-cp33m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp33-cp33m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 23.1 kB
- Tags: CPython 3.3m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d97bd89c0d5f1efce4425f76a45f7f63df486487fc0d2de9166373f53c52c9bc |
|
MD5 | 448b64bec7c5b2adb1bac5d8394e1707 |
|
BLAKE2b-256 | 089c822d0868f9183fdb0a6f5940dc07bc1020445c48131d1deb4a0691120300 |
File details
Details for the file fastnumbers-2.0.2-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 23.5 kB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b16f64575057a540f2f14d78b7e310afdc90b7ec6bf3aab623fb63b387d196c |
|
MD5 | fda884052a1376578d92e11d677f989f |
|
BLAKE2b-256 | bc95eb2c632ccd1288c6cd8d5da23888fd001e3a3ee015c66cb98b0343358d92 |
File details
Details for the file fastnumbers-2.0.2-cp27-cp27m-win32.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp27-cp27m-win32.whl
- Upload date:
- Size: 23.5 kB
- Tags: CPython 2.7m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6757f31d2b5ce0f2a5226d0668eb44e3f67875834a61e94b86d02d18d7ac1f1e |
|
MD5 | 3f4535e6e959e02841c7707319de2e3a |
|
BLAKE2b-256 | 309afce4e55f7d21da64ed511f286fe2726f4cb122731807b554c409155deccd |
File details
Details for the file fastnumbers-2.0.2-cp27-cp27m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: fastnumbers-2.0.2-cp27-cp27m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 23.6 kB
- Tags: CPython 2.7m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5218f03b44fc6df1644b993399e647d12f0500bb53cbdf96bb392304c313a86 |
|
MD5 | fd22f5af114db74c96fa80cbd6709963 |
|
BLAKE2b-256 | c58b96eb592eef083693afc7482220675a92076af3c1f938ed7875f82cbe0548 |