engineering-notation 0.13.1__tar.gz → 0.13.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/PKG-INFO +1 -1
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation/eng_notation.py +11 -4
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation.egg-info/PKG-INFO +1 -1
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/pyproject.toml +1 -1
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/tests/test_engnum.py +20 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation/__init__.py +0 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation/version.py +0 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation.egg-info/SOURCES.txt +0 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation.egg-info/dependency_links.txt +0 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation.egg-info/top_level.txt +0 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/readme.md +0 -0
- {engineering_notation-0.13.1 → engineering_notation-0.13.2}/setup.cfg +0 -0
{engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation/eng_notation.py
RENAMED
|
@@ -97,7 +97,7 @@ class EngUnit:
|
|
|
97
97
|
def __init__(
|
|
98
98
|
self,
|
|
99
99
|
value: str | int | float | EngNumber | EngUnit,
|
|
100
|
-
precision: int =
|
|
100
|
+
precision: int | None = None,
|
|
101
101
|
significant: int = 0,
|
|
102
102
|
unit: str | None = None,
|
|
103
103
|
separator: str = "",
|
|
@@ -108,6 +108,7 @@ class EngUnit:
|
|
|
108
108
|
Args:
|
|
109
109
|
value: String, int, float, or EngNumber value to parse.
|
|
110
110
|
precision: Decimal places used when significant is 0.
|
|
111
|
+
Defaults to 2 when None.
|
|
111
112
|
significant: Significant digits; takes precedence over precision.
|
|
112
113
|
unit: Explicit unit suffix. If None, a unit suffix is parsed from
|
|
113
114
|
the end of a string value when present.
|
|
@@ -448,7 +449,7 @@ class EngNumber:
|
|
|
448
449
|
def __init__(
|
|
449
450
|
self,
|
|
450
451
|
value: str | int | float | EngNumber,
|
|
451
|
-
precision: int =
|
|
452
|
+
precision: int | None = None,
|
|
452
453
|
significant: int = 0,
|
|
453
454
|
separator: str = "",
|
|
454
455
|
) -> None:
|
|
@@ -458,6 +459,7 @@ class EngNumber:
|
|
|
458
459
|
Args:
|
|
459
460
|
value: String, int, float, or EngNumber value to parse.
|
|
460
461
|
precision: Decimal places used when significant is 0.
|
|
462
|
+
Defaults to 2 when None.
|
|
461
463
|
significant: Significant digits; takes precedence over precision.
|
|
462
464
|
separator: String inserted between the numeric value and suffix.
|
|
463
465
|
|
|
@@ -465,7 +467,8 @@ class EngNumber:
|
|
|
465
467
|
TypeError: If the value type is unsupported.
|
|
466
468
|
ValueError: If a string value cannot be parsed by Decimal.
|
|
467
469
|
"""
|
|
468
|
-
self.precision = precision
|
|
470
|
+
self.precision = 2 if precision is None else precision
|
|
471
|
+
self._precision_explicit = precision is not None
|
|
469
472
|
self.significant = significant
|
|
470
473
|
self.separator = separator
|
|
471
474
|
|
|
@@ -560,7 +563,11 @@ class EngNumber:
|
|
|
560
563
|
base = base.rstrip(".")
|
|
561
564
|
|
|
562
565
|
# remove trailing .00 in precision 2
|
|
563
|
-
if
|
|
566
|
+
if (
|
|
567
|
+
self.precision == 2
|
|
568
|
+
and self.significant == 0
|
|
569
|
+
and not self._precision_explicit
|
|
570
|
+
):
|
|
564
571
|
if ".00" in base:
|
|
565
572
|
base = base[:-3]
|
|
566
573
|
|
|
@@ -71,6 +71,20 @@ def test_engnum_significant():
|
|
|
71
71
|
assert str(EngNumber("2.22m", significant=3)) == "2.22m"
|
|
72
72
|
|
|
73
73
|
|
|
74
|
+
def test_engnum_precision_rounding():
|
|
75
|
+
assert str(EngNumber("1.234k", precision=1)) == "1.2k"
|
|
76
|
+
assert str(EngNumber("1.234k", precision=3)) == "1.234k"
|
|
77
|
+
assert str(EngNumber("1.2k", precision=0)) == "1k"
|
|
78
|
+
assert str(EngNumber("-1.234k", precision=1)) == "-1.2k"
|
|
79
|
+
assert str(EngNumber("1.666666", precision=2)) == "1.67"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_engnum_precision_trailing_zeros():
|
|
83
|
+
assert str(EngNumber("1k", precision=2)) == "1.00k"
|
|
84
|
+
assert str(EngNumber("1k", precision=3)) == "1.000k"
|
|
85
|
+
assert str(EngNumber("2.0", precision=2)) == "2.00"
|
|
86
|
+
|
|
87
|
+
|
|
74
88
|
def test_engnum_separator():
|
|
75
89
|
assert str(EngNumber("1.23k", separator=" ")) == "1.23 k"
|
|
76
90
|
assert str(EngNumber("1.23k", separator=" ").to_pn()) == "1k23"
|
|
@@ -366,6 +380,12 @@ def test_to_str():
|
|
|
366
380
|
assert EngUnit("2m", unit="meter").eng_num == EngNumber("2m")
|
|
367
381
|
|
|
368
382
|
|
|
383
|
+
def test_engunit_precision():
|
|
384
|
+
assert str(EngUnit("1.234kHz", precision=1)) == "1.2kHz"
|
|
385
|
+
assert str(EngUnit("1kHz", precision=3)) == "1.000kHz"
|
|
386
|
+
assert str(EngUnit("-1.234kHz", precision=1)) == "-1.2kHz"
|
|
387
|
+
|
|
388
|
+
|
|
369
389
|
def test_to_str_large():
|
|
370
390
|
# positive_numbers
|
|
371
391
|
assert str(EngUnit("220kHz")) == "220kHz"
|
{engineering_notation-0.13.1 → engineering_notation-0.13.2}/engineering_notation/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|