Skip to content

Commit f5e8aa4

Browse files
committed
v0.2.0 pre-release commit
- Changes to "setup.py". - Updated requirements. - Changed method name "set()" to "set_precision()". - Implemented strict typing. - Updates to docstring. - Changed parameter name "digit" to "number". - Updated README. Signed-off-by: schlopp96 <[email protected]>
1 parent 14ef9e0 commit f5e8aa4

File tree

6 files changed

+57
-38
lines changed

6 files changed

+57
-38
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- To install _**`SetPrecision`**_ using `pip`, enter the following:
1616

1717
```python
18-
pip install SetPrecision
18+
python -m pip install SetPrecision
1919
```
2020

2121
- Done!
@@ -28,15 +28,19 @@
2828
2929
1. Before use, navigate to intended installation location, and create a new directory.
3030

31-
2. Clone repository with the git client of your preference.
31+
2. Clone repository with the git client of your preference using the following command:
32+
33+
- ```bash
34+
git clone https://github.com/schlopp96/SetPrecision/releases/latest
35+
```
3236

3337
3. Install all dependencies for this package within said directory using:
3438

35-
```text
39+
- ```bash
3640
pip install -r requirements.txt
37-
```
41+
```
3842

39-
- (Optional) move installation directory to `"path/to/Python/Libs/site_packages"` to be able to import this package to a Python program like any other importable package.
43+
- **(Optional)**: move installation directory to `"path/to/Python/Libs/site_packages"` to be able to import this package to a Python program like any other importable package.
4044

4145
- Done!
4246

@@ -47,33 +51,33 @@
4751
- In order to use _**`SetPrecision`**_, start by importing the module to your Python environment:
4852

4953
```python
50-
from SetPrecision import set
54+
from SetPrecision import set_precision
5155
```
5256

53-
- Now, simply call the `set` method and enter your desired number to be formatted as the `digit` parameter, and the level of precision as the `precision` parameter:
57+
- Now, simply call the `set_precision` method and enter your desired number to be formatted as the `number` parameter, and the level of precision as the `precision` parameter:
5458

5559
```python
5660
5761
>>> testA = 3.141592653589793 # Not necessary to set number as variable.
5862
59-
>>> testA = set(testA, 2)
63+
>>> testA = set_precision(testA, 2)
6064
6165
>>> print(testA)
6266
6367
'3.15'
6468
6569
>>> testB = 3.141592653589793
6670
67-
>>> testB = set(testB, 4)
71+
>>> testB = set_precision(testB, 4)
6872
6973
>>> print(testB)
7074
7175
'3.1416'
7276
```
7377

74-
> Note that the output is automatically rounded up when `digit >= 5`, and down when `digit < 5`.
78+
> Note that the output is automatically rounded up when `number >= 5`, and down when `number < 5`.
7579

76-
- Both params can be entered in string format, and will output successfully assuming that both paramaters can be cast to their appropriate types.
80+
- Both params can be entered in string format, and will output successfully assuming that both parameters can be cast to their appropriate types.
7781
- This is done automatically.
7882

7983
---

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
setuptools==58.1.0
1+
setuptools>=58.1.0

setPrecision/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .SetPrecision import set
1+
from .SetPrecision import set_precision

setPrecision/setPrecision.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22
# -*- coding: utf-8 -*-
33

44

5-
def set(digit: float | str, precision: int | str = 1) -> str | Exception:
6-
"""Returns a string representation of a number :float:`digit` formatted to the given precision of :int:`precision` significant digits.
5+
def set_precision(number: float | str,
6+
precision: int | str = 1) -> str | Exception:
7+
"""Returns a string representation of a :param:`number` formatted to the given precision of :param:`precision` significant figures.
78
89
Example:
910
1011
```python
11-
>>> from SetPrecision import set
12-
>>> x = 3.1459 # Not necessary to set number as variable.
13-
>>> y = set(digit=x, precision=2)
14-
>>> print(y)
12+
>>> from SetPrecision import set_precision
13+
>>> decimal = set_precision(number=3.1459, precision=2)
14+
>>> print(decimal)
1515
'3.15'
1616
```
1717
1818
---
1919
20-
:param digit: float/decimal to be formatted. Will attempt to convert strings to floats.
21-
:type digit: float | str
22-
:param precision: number of decimal places to which `digit` is set to contain. Will attempt to convert strings to integers, defaults to 1.
23-
:type precision: int | str
24-
:return: final string representation of formatted float/decimal `digit`.
25-
:rtype: str
20+
:param number: float/decimal to be formatted. Will attempt to convert strings to floats
21+
:type number: :class:`float` | :class:`str`
22+
:param precision: number of decimal places to which :param:`number` is set to contain. Will attempt to convert strings to integers, defaults to 1
23+
:type precision: :class:`int` | :class:`str`, optional
24+
:return: final string representation of formatted float/decimal :param:`number`
25+
:rtype: :class:`str`
2626
"""
2727
try:
28-
digit = float(digit)
28+
number = float(number)
2929
precision = int(precision)
30-
return f"{digit:.{precision}f}"
30+
31+
return f"{number:.{precision}f}"
32+
3133
except Exception as exc:
3234
return exc
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
from ..SetPrecision import set
1+
from ..SetPrecision import set_precision
22

33

44
def test_setPrecisionA() -> None:
5-
assert set(3.1415926, 3) == '3.142'
5+
assert set_precision(3.1415926, 3) == '3.142'
66

77

88
def test_setPrecisionB() -> None:
9-
assert set(10.5, 0) == '10'
9+
assert set_precision(10.5, 0) == '10'
1010

1111

1212
def test_setPrecisionC() -> None:
13-
assert set(5280.40836894, 2) == '5280.41'
13+
assert set_precision(5280.40836894, 2) == '5280.41'
1414

1515

1616
def test_setPrecisionD() -> None:
17-
assert set(150, 5) == '150.00000'
17+
assert set_precision(150, 5) == '150.00000'
1818

1919

2020
def test_setPrecisionE() -> None:
21-
assert set(1485809.4861172) == '1485809.5'
21+
assert set_precision(1485809.4861172) == '1485809.5'

setup.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
reqs = pathlib.Path("requirements.txt").read_text()
66
setup(
77
name="SetPrecision",
8-
version="0.1.0",
8+
version="0.2.0",
99
description=
10-
"`SetPrecision` is a small module providing a simple way to set the precision of a floating point number or decimal to the desired amount of significant digits.",
10+
"Python module providing an easy way to set the precision of a floating-point number/decimal to the desired amount of significant figures.",
1111
url='https://github.com/schlopp96/SetPrecision',
1212
author='schlopp96',
1313
author_email='[email protected]',
@@ -31,7 +31,20 @@
3131
"Topic :: Utilities",
3232
],
3333
keywords=[
34-
'SetPrecision', 'float', 'decimal', 'precision', 'sig', 'figs',
35-
'significant', 'digits', 'scientific', 'notation', 'math',
36-
'conversion', 'script', 'point', 'floating'
34+
'SetPrecision',
35+
'float',
36+
'decimal',
37+
'precision',
38+
'sig',
39+
'figs',
40+
'significant',
41+
'digits',
42+
'scientific',
43+
'notation',
44+
'math',
45+
'conversion',
46+
'script',
47+
'point',
48+
'floating',
49+
'scientific-notation',
3750
])

0 commit comments

Comments
 (0)