engineering-notation


Nameengineering-notation JSON
Version 0.10.0 PyPI version JSON
download
home_pagehttps://github.com/slightlynybbled/engineering_notation
SummaryEasy engineering notation
upload_time2023-10-11 10:34:59
maintainer
docs_urlNone
authorJason R. Jones
requires_python
licenseMIT
keywords engineering notation decimal
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Unit Tests](https://github.com/slightlynybbled/engineering_notation/actions/workflows/unittest.yml/badge.svg)](https://github.com/slightlynybbled/engineering_notation/actions/workflows/unittest.yml)

# 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.

More information may be found at [for(embed)](http://forembed.com/engineering-notation-in-python.html).

# Installation

Install using pip: `pip install engineering_notation`.

# Status and Contributions

This project currently has 100% test coverage.  Have a look in `test.py` for examples of how to use
this library. To execute the tests, run `pytest` from the main directory or, 
in some environments, it may be necessary to run `python3 -m pytest`.

Any contributions must pass 100% of current tests and pass flake8.  To execute
flake8, navigate to the project directory and `python3 setup.py flake8`.

Your pull request will automatically be run through testing and flake8 checks and
any pull requests that do not pass these will be put on hold pending passing.

# Use 

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/slightlynybbled/engineering_notation",
    "name": "engineering-notation",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "engineering notation decimal",
    "author": "Jason R. Jones",
    "author_email": "slightlynybbled@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "[![Unit Tests](https://github.com/slightlynybbled/engineering_notation/actions/workflows/unittest.yml/badge.svg)](https://github.com/slightlynybbled/engineering_notation/actions/workflows/unittest.yml)\r\n\r\n# Purpose\r\n\r\nTo easily work with human-readable engineering notation.  I wrote this as a quick tool for my own use.\r\nI found that I was writing the same functionality into multiple packages and would like a quick pip-installable\r\npackage to take care of this manipulation for me.  The package should be easily extended for other use cases.\r\nThe package is unit-less, so only operates on numeric values.  Unit detection may be added in future versions.\r\n\r\nMore information may be found at [for(embed)](http://forembed.com/engineering-notation-in-python.html).\r\n\r\n# Installation\r\n\r\nInstall using pip: `pip install engineering_notation`.\r\n\r\n# Status and Contributions\r\n\r\nThis project currently has 100% test coverage.  Have a look in `test.py` for examples of how to use\r\nthis library. To execute the tests, run `pytest` from the main directory or, \r\nin some environments, it may be necessary to run `python3 -m pytest`.\r\n\r\nAny contributions must pass 100% of current tests and pass flake8.  To execute\r\nflake8, navigate to the project directory and `python3 setup.py flake8`.\r\n\r\nYour pull request will automatically be run through testing and flake8 checks and\r\nany pull requests that do not pass these will be put on hold pending passing.\r\n\r\n# Use \r\n\r\nThere are multiple ways of initializing a number to a particular value, but a string is the preferred method:\r\n\r\n```\r\n>>> from engineering_notation import EngNumber\r\n>>> EngNumber('10k')\r\n10k\r\n>>> EngNumber('10000')\r\n10k\r\n>>> EngNumber(10000)\r\n10k\r\n>>> EngNumber(10000.0)\r\n10k\r\n>>> EngNumber(1e4)\r\n10k\r\n```\r\n\r\nWhere decimals are involved, we use a default precision of 2 digits:\r\n\r\n```\r\n>>> EngNumber('4.99k')\r\n4.99k\r\n>>> EngNumber('4.9k')\r\n4.90k\r\n```\r\n\r\nThis behavior can truncate your results in some cases, and cause your number to round.  To specify more or less\r\ndigits, simply specify the precision in the declaration:\r\n\r\n```\r\n>>> EngNumber('4.999k')\r\n5k\r\n>>> EngNumber('4.999k', precision=3)\r\n4.999k\r\n```\r\n\r\nMost operations that you would perform on numeric values are valid, although all operations are not implemented:\r\n\r\n```\r\n>>> EngNumber('2.2k') * 2\r\n4.40k\r\n>>> 2 * EngNumber('2.2k')\r\n4.40k\r\n>>> EngNumber(1.2) > EngNumber('3.3k') \r\nFalse\r\n>>> EngNumber(1.2) <= EngNumber('3.3k')\r\nTrue\r\n>>> EngNumber('3.3k') == EngNumber(3300)\r\nTrue\r\n```\r\n\r\nAll of the above operations are also possible on the `EngUnit()` class as well.  The only difference is\r\nthat units must match for addition/subtraction/comparison operations.  Although multiplication and division\r\noperations will work numerically, they may not always be strictly correct.  This is because EngUnit is not\r\nintended to replace a computer algebra system!\r\n\r\n```\r\n>>> EngUnit('2s') / EngUnit('4rotations')\r\n0.5s/rotations\r\n```\r\n\r\nAdditionally, since there are 'reserved' letters for sizing the number, you must be careful with your units!\r\n\r\n```\r\n>>> EngUnit('2mm')\r\n2mm        # <<< this value equivalent to \"0.002m\"\r\n>>> EngUnit('2meter')\r\n2meter     # <<< this value is equivalent to \"0.002eter\", the \"m\" was used to scale the unit!\r\n>>> EngUnit('2', unit='meter')   # <<< this will work better\r\n```\r\n\r\n# Contributions\r\n\r\nContributions are welcome.  Feel free to make feature requests in the issues.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Easy engineering notation",
    "version": "0.10.0",
    "project_urls": {
        "Homepage": "https://github.com/slightlynybbled/engineering_notation"
    },
    "split_keywords": [
        "engineering",
        "notation",
        "decimal"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "291ecf61798657ff598417693ed1b4552afa9300203120e4fe84809ec1c3f157",
                "md5": "b18cda5ade7554cee14c4e90b4ff3fdd",
                "sha256": "49ff22ba8377673c8cd5f45298b87c41946b5a84583806a4655760124e22c451"
            },
            "downloads": -1,
            "filename": "engineering_notation-0.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b18cda5ade7554cee14c4e90b4ff3fdd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6769,
            "upload_time": "2023-10-11T10:34:59",
            "upload_time_iso_8601": "2023-10-11T10:34:59.434336Z",
            "url": "https://files.pythonhosted.org/packages/29/1e/cf61798657ff598417693ed1b4552afa9300203120e4fe84809ec1c3f157/engineering_notation-0.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-11 10:34:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "slightlynybbled",
    "github_project": "engineering_notation",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "engineering-notation"
}
        
Elapsed time: 0.26517s