Skip to main content

Unit Tests

Purpose

To easily work with human-readable engineering notation. I wrote this as a quick tool for my own use. I found that I was writing the same functionality into multiple packages and would like a quick pip-installable package to take care of this manipulation for me. The package should be easily extended for other use cases. The package is unit-less, so only operates on numeric values. Unit detection may be added in future versions.

Installation

Install using pip or uv:

pip install engineering_notation
uv add engineering_notation

Usage

There are multiple ways of initializing a number to a particular value, but a string is the preferred method:

>>> from engineering_notation import EngNumber
>>> EngNumber('10k')
10k
>>> EngNumber('10000')
10k
>>> EngNumber(10000)
10k
>>> EngNumber(10000.0)
10k
>>> EngNumber(1e4)
10k

Where decimals are involved, we use a default precision of 2 digits:

>>> EngNumber('4.99k')
4.99k
>>> EngNumber('4.9k')
4.90k

This behavior can truncate your results in some cases, and cause your number to round. To specify more or less digits, simply specify the precision in the declaration:

>>> EngNumber('4.999k')
5k
>>> EngNumber('4.999k', precision=3)
4.999k

Most operations that you would perform on numeric values are valid, although all operations are not implemented:

>>> EngNumber('2.2k') * 2
4.40k
>>> 2 * EngNumber('2.2k')
4.40k
>>> EngNumber(1.2) > EngNumber('3.3k') 
False
>>> EngNumber(1.2) <= EngNumber('3.3k')
True
>>> EngNumber('3.3k') == EngNumber(3300)
True

All of the above operations are also possible on the EngUnit() class as well. The only difference is that units must match for addition/subtraction/comparison operations. Although multiplication and division operations will work numerically, they may not always be strictly correct. This is because EngUnit is not intended to replace a computer algebra system!

>>> EngUnit('2s') / EngUnit('4rotations')
0.5s/rotations

Additionally, since there are 'reserved' letters for sizing the number, you must be careful with your units!

>>> EngUnit('2mm')
2mm        # <<< this value equivalent to "0.002m"
>>> EngUnit('2meter')
2meter     # <<< this value is equivalent to "0.002eter", the "m" was used to scale the unit!
>>> EngUnit('2', unit='meter')   # <<< this will work better

Contributions

Contributions are welcome. Feel free to make feature requests in the issues.

Running Tests

If you are developing, you probably want to perform a local editable installation:

uv run -m pytest

Metadata

Release files for engineering-notation 0.13.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for engineering-notation 0.13.3
File Size Uploaded
engineering_notation-0.13.3.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for engineering-notation 0.13.3
File Interpreter ABI Platform
engineering_notation-0.13.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / engineering_notation-0.13.3.tar.gz

Download URL engineering_notation-0.13.3.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a8cb3dacc0ffc3f756f0ca47f7e20d7b27d87acd5e871a08676967e1286b058d
BLAKE2b-256 checksum
How to use checksums
90951307de8d2d77083d2edd85967510e4894d1c51bfbe2fea7ce3cf04d49870
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / engineering_notation-0.13.3-py3-none-any.whl

Download URL engineering_notation-0.13.3-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3059f9302784df698848138d190dd99374b8b712c22941ff1b2b1ff99feab43c
BLAKE2b-256 checksum
How to use checksums
8c12e74fec20623a9b60bfc915242b6151a2b6dbcfb3d3e30a0b9cea601e8d4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.13.3 This release

2 release files

0.12.0

2 release files

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.2

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.0

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page