quantiphy 2.21__tar.gz → 2.22__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.
- {quantiphy-2.21 → quantiphy-2.22}/LICENSE +1 -1
- {quantiphy-2.21 → quantiphy-2.22}/PKG-INFO +3 -3
- {quantiphy-2.21 → quantiphy-2.22}/README.rst +2 -2
- {quantiphy-2.21 → quantiphy-2.22}/pyproject.toml +1 -1
- {quantiphy-2.21 → quantiphy-2.22}/quantiphy/quantiphy.py +39 -11
- {quantiphy-2.21 → quantiphy-2.22}/quantiphy/quantiphy.pyi +1 -0
- {quantiphy-2.21 → quantiphy-2.22}/quantiphy/__init__.py +0 -0
- {quantiphy-2.21 → quantiphy-2.22}/quantiphy/__init__.pyi +0 -0
- {quantiphy-2.21 → quantiphy-2.22}/quantiphy/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantiphy
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.22
|
|
4
4
|
Summary: physical quantities (numbers with units)
|
|
5
5
|
Keywords: quantities,physical quantity,units,SI scale factors,engineering notation,mks,cgs
|
|
6
6
|
Author: Ken Kundert
|
|
@@ -28,8 +28,8 @@ QuantiPhy — Physical Quantities
|
|
|
28
28
|
|downloads| |build status| |coverage| |rtd status| |pypi version| |anaconda version| |python version|
|
|
29
29
|
|
|
30
30
|
| Author: Ken Kundert
|
|
31
|
-
| Version: 2.
|
|
32
|
-
| Released:
|
|
31
|
+
| Version: 2.22
|
|
32
|
+
| Released: 2026-06-27
|
|
33
33
|
|
|
|
34
34
|
|
|
35
35
|
|
|
@@ -22,7 +22,7 @@ Documentation can be found at https://quantiphy.readthedocs.io.
|
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
24
|
# MIT License {{{1
|
|
25
|
-
# Copyright (C) 2016-
|
|
25
|
+
# Copyright (C) 2016-2026 Kenneth S. Kundert
|
|
26
26
|
#
|
|
27
27
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
28
|
# of this software and associated documentation files (the "Software"), to deal
|
|
@@ -375,8 +375,8 @@ def add_constant(value, alias=None, unit_systems=None):
|
|
|
375
375
|
|
|
376
376
|
|
|
377
377
|
# Globals {{{1
|
|
378
|
-
__version__ = '2.
|
|
379
|
-
__released__ = '
|
|
378
|
+
__version__ = '2.22'
|
|
379
|
+
__released__ = '2026-06-27'
|
|
380
380
|
|
|
381
381
|
# These mappings are only used when reading numbers
|
|
382
382
|
# The key for these mappings must be a single character
|
|
@@ -499,6 +499,8 @@ DEFAULTS = dict(
|
|
|
499
499
|
output_sf = 'TGMkmunpfa',
|
|
500
500
|
plus = '+',
|
|
501
501
|
prec = 4,
|
|
502
|
+
preferred_quantities = {},
|
|
503
|
+
_preferred_quantities = {}, # transposed version of preferred_quantities
|
|
502
504
|
preferred_units = {},
|
|
503
505
|
_preferred_units = {}, # transposed version of preferred_units
|
|
504
506
|
radix = '.',
|
|
@@ -967,6 +969,14 @@ class Quantity(float):
|
|
|
967
969
|
full precision is not required. Default is 4.
|
|
968
970
|
:type prec: int or str
|
|
969
971
|
|
|
972
|
+
:arg dict preferred_quantities:
|
|
973
|
+
A dictionary that is used when looking up the preferred quantity when
|
|
974
|
+
instantiating. For example, if *preferred_quantities* contains the entry:
|
|
975
|
+
{Decibels: “dB dBV dBA dBm dBc”} where *Decibels* is a subclass of
|
|
976
|
+
*Quantity*, then when instantiating a quantity with units “dB”, “dBV”,
|
|
977
|
+
“dBA”, “dBm”, or “dBc”, the quantity returned would have *Decibels*
|
|
978
|
+
as its class.
|
|
979
|
+
|
|
970
980
|
:arg dict preferred_units:
|
|
971
981
|
A dictionary that is used when looking up the preferred units when
|
|
972
982
|
rendering. For example, if *preferred_units* contains the entry:
|
|
@@ -1092,13 +1102,21 @@ class Quantity(float):
|
|
|
1092
1102
|
if isinstance(kwargs.get('known_units'), str):
|
|
1093
1103
|
kwargs['known_units'] = kwargs['known_units'].split()
|
|
1094
1104
|
|
|
1105
|
+
# split preferred_quantities
|
|
1106
|
+
if 'preferred_quantities' in kwargs:
|
|
1107
|
+
kwargs['_preferred_quantities'] = {
|
|
1108
|
+
unit : quantity
|
|
1109
|
+
for quantity, units in kwargs['preferred_quantities'].items()
|
|
1110
|
+
for unit in units.split()
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1095
1113
|
# split preferred_units
|
|
1096
1114
|
if 'preferred_units' in kwargs:
|
|
1097
|
-
_preferred_units = {
|
|
1098
|
-
|
|
1099
|
-
for
|
|
1100
|
-
|
|
1101
|
-
|
|
1115
|
+
kwargs['_preferred_units'] = {
|
|
1116
|
+
unit : preferred
|
|
1117
|
+
for preferred, units in kwargs['preferred_units'].items()
|
|
1118
|
+
for unit in units.split()
|
|
1119
|
+
}
|
|
1102
1120
|
|
|
1103
1121
|
# check for unknown output scale factors
|
|
1104
1122
|
if kwargs.get('output_sf'):
|
|
@@ -1715,7 +1733,13 @@ class Quantity(float):
|
|
|
1715
1733
|
|
|
1716
1734
|
# create the underlying data structure and add attributes {{{3
|
|
1717
1735
|
try:
|
|
1718
|
-
|
|
1736
|
+
preferred_quantities = cls._preferences["_preferred_quantities"]
|
|
1737
|
+
preferred_quantity = preferred_quantities[units]
|
|
1738
|
+
assert issubclass(preferred_quantity, cls)
|
|
1739
|
+
except (AttributeError, KeyError):
|
|
1740
|
+
preferred_quantity = cls
|
|
1741
|
+
try:
|
|
1742
|
+
self = float.__new__(preferred_quantity, number)
|
|
1719
1743
|
except TypeError:
|
|
1720
1744
|
raise InvalidNumber(number)
|
|
1721
1745
|
if units:
|
|
@@ -2971,7 +2995,8 @@ class Quantity(float):
|
|
|
2971
2995
|
end = match.start(0)
|
|
2972
2996
|
number = match.group(0)
|
|
2973
2997
|
try:
|
|
2974
|
-
|
|
2998
|
+
q = cls.__new__(cls, number)
|
|
2999
|
+
number = q.render(**kwargs)
|
|
2975
3000
|
except ValueError: # pragma: no cover
|
|
2976
3001
|
# something unexpected happened
|
|
2977
3002
|
# but this is not essential, so ignore it
|
|
@@ -3020,7 +3045,8 @@ class Quantity(float):
|
|
|
3020
3045
|
end = match.start(0)
|
|
3021
3046
|
number = match.group(0)
|
|
3022
3047
|
try:
|
|
3023
|
-
|
|
3048
|
+
q = cls.__new__(cls, number)
|
|
3049
|
+
number = q.render(**kwargs)
|
|
3024
3050
|
except ValueError: # pragma: no cover
|
|
3025
3051
|
# something unexpected happened
|
|
3026
3052
|
# but this is not essential, so ignore it
|
|
@@ -3864,3 +3890,5 @@ def binary(value, units, params=None, *args, **kwargs):
|
|
|
3864
3890
|
|
|
3865
3891
|
"""
|
|
3866
3892
|
return Quantity(value, units=units, params=params).binary(*args, **kwargs)
|
|
3893
|
+
|
|
3894
|
+
# vim: set sw=4 sts=4 tw=80 fo=ntcqwa12 et spell:
|
|
@@ -119,6 +119,7 @@ class Quantity(float):
|
|
|
119
119
|
show_label: bool | str = ...,
|
|
120
120
|
strip_zeros: bool = ...,
|
|
121
121
|
strip_radix: bool = ...,
|
|
122
|
+
spacer: str | bool = ...,
|
|
122
123
|
scale: str | float | tuple[float | Quantity, str] | Callable = ...,
|
|
123
124
|
negligible: float = ...,
|
|
124
125
|
) -> str: ...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|