quantiphy 2.19__tar.gz → 2.20__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.19 → quantiphy-2.20}/PKG-INFO +27 -21
- {quantiphy-2.19 → quantiphy-2.20}/README.rst +26 -20
- {quantiphy-2.19 → quantiphy-2.20}/pyproject.toml +1 -1
- {quantiphy-2.19 → quantiphy-2.20}/quantiphy/quantiphy.py +48 -51
- {quantiphy-2.19 → quantiphy-2.20}/quantiphy/quantiphy.pyi +1 -1
- {quantiphy-2.19 → quantiphy-2.20}/quantiphy/__init__.py +0 -0
- {quantiphy-2.19 → quantiphy-2.20}/quantiphy/__init__.pyi +0 -0
- {quantiphy-2.19 → quantiphy-2.20}/quantiphy/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: quantiphy
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.20
|
|
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
|
|
@@ -24,28 +24,11 @@ Project-URL: repository, https://github.com/kenkundert/quantiphy
|
|
|
24
24
|
QuantiPhy — Physical Quantities
|
|
25
25
|
===============================
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
:target: https://pepy.tech/project/quantiphy
|
|
29
|
-
|
|
30
|
-
.. image:: https://img.shields.io/readthedocs/quantiphy.svg
|
|
31
|
-
:target: https://quantiphy.readthedocs.io/en/latest/?badge=latest
|
|
32
|
-
|
|
33
|
-
.. image:: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml/badge.svg
|
|
34
|
-
:target: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml
|
|
35
|
-
|
|
36
|
-
.. image:: https://coveralls.io/repos/github/KenKundert/quantiphy/badge.svg?branch=master
|
|
37
|
-
:target: https://coveralls.io/github/KenKundert/quantiphy?branch=master
|
|
38
|
-
|
|
39
|
-
.. image:: https://img.shields.io/pypi/v/quantiphy.svg
|
|
40
|
-
:target: https://pypi.python.org/pypi/quantiphy
|
|
41
|
-
|
|
42
|
-
.. image:: https://img.shields.io/pypi/pyversions/quantiphy.svg
|
|
43
|
-
:target: https://pypi.python.org/pypi/quantiphy/
|
|
44
|
-
|
|
27
|
+
|downloads| |build status| |coverage| |rtd status| |pypi version| |anaconda version| |python version|
|
|
45
28
|
|
|
46
29
|
| Author: Ken Kundert
|
|
47
|
-
| Version: 2.
|
|
48
|
-
| Released:
|
|
30
|
+
| Version: 2.20
|
|
31
|
+
| Released: 2024-04-27
|
|
49
32
|
|
|
|
50
33
|
|
|
51
34
|
|
|
@@ -228,3 +211,26 @@ incorporate quantity values into strings:
|
|
|
228
211
|
*QuantiPhy* has many more features and capabilities. For more information, view
|
|
229
212
|
the `documentation <https://quantiphy.readthedocs.io>`_.
|
|
230
213
|
|
|
214
|
+
|
|
215
|
+
.. |downloads| image:: https://pepy.tech/badge/quantiphy/month
|
|
216
|
+
:target: https://pepy.tech/project/quantiphy
|
|
217
|
+
|
|
218
|
+
.. |rtd status| image:: https://img.shields.io/readthedocs/quantiphy.svg
|
|
219
|
+
:target: https://quantiphy.readthedocs.io/en/latest/?badge=latest
|
|
220
|
+
|
|
221
|
+
.. |build status| image:: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml/badge.svg
|
|
222
|
+
:target: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml
|
|
223
|
+
|
|
224
|
+
.. |coverage| image:: https://coveralls.io/repos/github/KenKundert/quantiphy/badge.svg?branch=master
|
|
225
|
+
:target: https://coveralls.io/github/KenKundert/quantiphy?branch=master
|
|
226
|
+
|
|
227
|
+
.. |pypi version| image:: https://img.shields.io/pypi/v/quantiphy.svg
|
|
228
|
+
:target: https://pypi.python.org/pypi/quantiphy
|
|
229
|
+
|
|
230
|
+
.. |anaconda version| image:: https://anaconda.org/conda-forge/quantiphy/badges/version.svg
|
|
231
|
+
:target: https://anaconda.org/conda-forge/quantiphy
|
|
232
|
+
|
|
233
|
+
.. |python version| image:: https://img.shields.io/pypi/pyversions/quantiphy.svg
|
|
234
|
+
:target: https://pypi.python.org/pypi/quantiphy/
|
|
235
|
+
|
|
236
|
+
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
QuantiPhy — Physical Quantities
|
|
2
2
|
===============================
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
:target: https://pepy.tech/project/quantiphy
|
|
6
|
-
|
|
7
|
-
.. image:: https://img.shields.io/readthedocs/quantiphy.svg
|
|
8
|
-
:target: https://quantiphy.readthedocs.io/en/latest/?badge=latest
|
|
9
|
-
|
|
10
|
-
.. image:: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml/badge.svg
|
|
11
|
-
:target: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml
|
|
12
|
-
|
|
13
|
-
.. image:: https://coveralls.io/repos/github/KenKundert/quantiphy/badge.svg?branch=master
|
|
14
|
-
:target: https://coveralls.io/github/KenKundert/quantiphy?branch=master
|
|
15
|
-
|
|
16
|
-
.. image:: https://img.shields.io/pypi/v/quantiphy.svg
|
|
17
|
-
:target: https://pypi.python.org/pypi/quantiphy
|
|
18
|
-
|
|
19
|
-
.. image:: https://img.shields.io/pypi/pyversions/quantiphy.svg
|
|
20
|
-
:target: https://pypi.python.org/pypi/quantiphy/
|
|
21
|
-
|
|
4
|
+
|downloads| |build status| |coverage| |rtd status| |pypi version| |anaconda version| |python version|
|
|
22
5
|
|
|
23
6
|
| Author: Ken Kundert
|
|
24
|
-
| Version: 2.
|
|
25
|
-
| Released:
|
|
7
|
+
| Version: 2.20
|
|
8
|
+
| Released: 2024-04-27
|
|
26
9
|
|
|
|
27
10
|
|
|
28
11
|
|
|
@@ -204,3 +187,26 @@ incorporate quantity values into strings:
|
|
|
204
187
|
|
|
205
188
|
*QuantiPhy* has many more features and capabilities. For more information, view
|
|
206
189
|
the `documentation <https://quantiphy.readthedocs.io>`_.
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
.. |downloads| image:: https://pepy.tech/badge/quantiphy/month
|
|
193
|
+
:target: https://pepy.tech/project/quantiphy
|
|
194
|
+
|
|
195
|
+
.. |rtd status| image:: https://img.shields.io/readthedocs/quantiphy.svg
|
|
196
|
+
:target: https://quantiphy.readthedocs.io/en/latest/?badge=latest
|
|
197
|
+
|
|
198
|
+
.. |build status| image:: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml/badge.svg
|
|
199
|
+
:target: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml
|
|
200
|
+
|
|
201
|
+
.. |coverage| image:: https://coveralls.io/repos/github/KenKundert/quantiphy/badge.svg?branch=master
|
|
202
|
+
:target: https://coveralls.io/github/KenKundert/quantiphy?branch=master
|
|
203
|
+
|
|
204
|
+
.. |pypi version| image:: https://img.shields.io/pypi/v/quantiphy.svg
|
|
205
|
+
:target: https://pypi.python.org/pypi/quantiphy
|
|
206
|
+
|
|
207
|
+
.. |anaconda version| image:: https://anaconda.org/conda-forge/quantiphy/badges/version.svg
|
|
208
|
+
:target: https://anaconda.org/conda-forge/quantiphy
|
|
209
|
+
|
|
210
|
+
.. |python version| image:: https://img.shields.io/pypi/pyversions/quantiphy.svg
|
|
211
|
+
:target: https://pypi.python.org/pypi/quantiphy/
|
|
212
|
+
|
|
@@ -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-2024 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
|
|
@@ -62,7 +62,7 @@ def _scale(scale, unscaled):
|
|
|
62
62
|
# scale (what you want) scale is scaling factor or function, or to_units
|
|
63
63
|
# unscaled (what you have), a quantity
|
|
64
64
|
|
|
65
|
-
# allow
|
|
65
|
+
# allow subclass of Quantity that has units to be the scale
|
|
66
66
|
try:
|
|
67
67
|
if issubclass(scale, Quantity):
|
|
68
68
|
scale = scale.units
|
|
@@ -77,7 +77,7 @@ def _scale(scale, unscaled):
|
|
|
77
77
|
# otherwise, it might be a function
|
|
78
78
|
try:
|
|
79
79
|
scaled, to_units = scale(unscaled, unscaled.units)
|
|
80
|
-
|
|
80
|
+
# passing units as second argument is redundant, deprecated
|
|
81
81
|
except TypeError:
|
|
82
82
|
# otherwise, assume it is a scale factor
|
|
83
83
|
try:
|
|
@@ -367,38 +367,38 @@ def add_constant(value, alias=None, unit_systems=None):
|
|
|
367
367
|
|
|
368
368
|
|
|
369
369
|
# Globals {{{1
|
|
370
|
-
__version__ = '2.
|
|
371
|
-
__released__ = '
|
|
370
|
+
__version__ = '2.20'
|
|
371
|
+
__released__ = '2024-04-27'
|
|
372
372
|
|
|
373
373
|
# These mappings are only used when reading numbers
|
|
374
374
|
# The key for these mappings must be a single character
|
|
375
375
|
MAPPINGS = {
|
|
376
|
-
'Q': 'e30',
|
|
377
|
-
'R': 'e27',
|
|
378
|
-
'Y': 'e24',
|
|
379
|
-
'Z': 'e21',
|
|
380
|
-
'E': 'e18',
|
|
381
|
-
'P': 'e15',
|
|
382
|
-
'T': 'e12',
|
|
383
|
-
'G': 'e9',
|
|
384
|
-
'M': 'e6',
|
|
385
|
-
'K': 'e3',
|
|
386
|
-
'k': 'e3',
|
|
387
|
-
'_': 'e0',
|
|
388
|
-
'c': 'e-2',
|
|
389
|
-
'%': 'e-2',
|
|
390
|
-
'm': 'e-3',
|
|
391
|
-
'u': 'e-6',
|
|
392
|
-
'µ': 'e-6',
|
|
393
|
-
'μ': 'e-6',
|
|
394
|
-
'n': 'e-9',
|
|
395
|
-
'p': 'e-12',
|
|
396
|
-
'f': 'e-15',
|
|
397
|
-
'a': 'e-18',
|
|
398
|
-
'z': 'e-21',
|
|
399
|
-
'y': 'e-24',
|
|
400
|
-
'r': 'e-27',
|
|
401
|
-
'q': 'e-30',
|
|
376
|
+
'Q': 'e30', # quetta
|
|
377
|
+
'R': 'e27', # ronna
|
|
378
|
+
'Y': 'e24', # yotta
|
|
379
|
+
'Z': 'e21', # zetta
|
|
380
|
+
'E': 'e18', # exa
|
|
381
|
+
'P': 'e15', # peta
|
|
382
|
+
'T': 'e12', # tera
|
|
383
|
+
'G': 'e9', # giga
|
|
384
|
+
'M': 'e6', # mega
|
|
385
|
+
'K': 'e3', # kilo
|
|
386
|
+
'k': 'e3', # kilo
|
|
387
|
+
'_': 'e0', # unity
|
|
388
|
+
'c': 'e-2', # centi, only available for input, not used in output
|
|
389
|
+
'%': 'e-2', # percent, potentially available for input, not used in output
|
|
390
|
+
'm': 'e-3', # milli
|
|
391
|
+
'u': 'e-6', # micro (ASCII)
|
|
392
|
+
'µ': 'e-6', # micro (unicode micro)
|
|
393
|
+
'μ': 'e-6', # micro (unicode greek mu)
|
|
394
|
+
'n': 'e-9', # nano
|
|
395
|
+
'p': 'e-12', # pico
|
|
396
|
+
'f': 'e-15', # femto
|
|
397
|
+
'a': 'e-18', # ato
|
|
398
|
+
'z': 'e-21', # zepto
|
|
399
|
+
'y': 'e-24', # yocto
|
|
400
|
+
'r': 'e-27', # ronto
|
|
401
|
+
'q': 'e-30', # quecto
|
|
402
402
|
}
|
|
403
403
|
ALL_SF = ''.join(MAPPINGS.keys())
|
|
404
404
|
BINARY_MAPPINGS = {
|
|
@@ -1652,7 +1652,6 @@ class Quantity(float):
|
|
|
1652
1652
|
|
|
1653
1653
|
# perform scaling {{{3
|
|
1654
1654
|
# scaling can either be explicitly requested using scale parameter
|
|
1655
|
-
original = number
|
|
1656
1655
|
if scale or isinstance(scale, numbers.Number):
|
|
1657
1656
|
try:
|
|
1658
1657
|
unscaled = Quantity(number, units, params=params)
|
|
@@ -1774,9 +1773,10 @@ class Quantity(float):
|
|
|
1774
1773
|
the units, so the second argument is redundant and will eventually
|
|
1775
1774
|
be deprecated. The function returns two values, the value and
|
|
1776
1775
|
units of the new value.
|
|
1777
|
-
- If a string, it is taken to the be desired units
|
|
1778
|
-
with the units of the quantity are
|
|
1779
|
-
conversion, which is applied to create
|
|
1776
|
+
- If a string, it is taken to the be desired units, perhaps with a
|
|
1777
|
+
scale factor. This value along with the units of the quantity are
|
|
1778
|
+
used to select a known unit conversion, which is applied to create
|
|
1779
|
+
the new value.
|
|
1780
1780
|
- If a quantity, the units are ignored and the scale is treated as
|
|
1781
1781
|
if were specified as a unitless float.
|
|
1782
1782
|
- If a subclass of :class:`Quantity` that includes units, the units
|
|
@@ -1803,7 +1803,7 @@ class Quantity(float):
|
|
|
1803
1803
|
|
|
1804
1804
|
"""
|
|
1805
1805
|
|
|
1806
|
-
# if
|
|
1806
|
+
# if subclass of Quantity is passed as scale, use as cls if not given
|
|
1807
1807
|
try:
|
|
1808
1808
|
if issubclass(scale, Quantity) and not cls:
|
|
1809
1809
|
cls = scale
|
|
@@ -1852,13 +1852,10 @@ class Quantity(float):
|
|
|
1852
1852
|
|
|
1853
1853
|
try:
|
|
1854
1854
|
if check_units and self.units != addend.units:
|
|
1855
|
-
raise IncompatibleUnits(self
|
|
1855
|
+
raise IncompatibleUnits(self, addend)
|
|
1856
1856
|
except AttributeError:
|
|
1857
1857
|
if check_units == 'strict':
|
|
1858
|
-
raise IncompatibleUnits(
|
|
1859
|
-
getattr(self, 'units', None),
|
|
1860
|
-
getattr(addend, 'units', None)
|
|
1861
|
-
)
|
|
1858
|
+
raise IncompatibleUnits(self, addend)
|
|
1862
1859
|
new = self.__class__(self.real + addend, self.units)
|
|
1863
1860
|
new._inherit_attributes(self)
|
|
1864
1861
|
return new
|
|
@@ -2371,7 +2368,7 @@ class Quantity(float):
|
|
|
2371
2368
|
units = self._preferred_units.get(self.units, self.units) if show_units else ''
|
|
2372
2369
|
if prec is None:
|
|
2373
2370
|
prec = self.prec
|
|
2374
|
-
|
|
2371
|
+
if prec == 'full':
|
|
2375
2372
|
prec = self.full_prec
|
|
2376
2373
|
|
|
2377
2374
|
# check for infinities or NaN {{{3
|
|
@@ -2579,6 +2576,7 @@ class Quantity(float):
|
|
|
2579
2576
|
scale = units if units else None
|
|
2580
2577
|
prec = int(prec) if prec else None
|
|
2581
2578
|
ftype = ftype if ftype else ''
|
|
2579
|
+
alt_form = dict(strip_zeros=False, strip_radix=False) if alt_form else {}
|
|
2582
2580
|
if ftype and ftype in 'dnu':
|
|
2583
2581
|
if ftype == 'u':
|
|
2584
2582
|
value = scale if scale else self.units
|
|
@@ -2593,28 +2591,28 @@ class Quantity(float):
|
|
|
2593
2591
|
ftype = ftype.lower()
|
|
2594
2592
|
if ftype in 's': # note that ftype = '' matches this case
|
|
2595
2593
|
label = label if ftype else None
|
|
2596
|
-
value = self.render(
|
|
2594
|
+
value = self.render(
|
|
2595
|
+
prec=prec, show_label=label, scale=scale, **alt_form
|
|
2596
|
+
)
|
|
2597
2597
|
elif ftype == 'q':
|
|
2598
2598
|
value = self.render(
|
|
2599
2599
|
form='si', prec=prec, show_units=True, show_label=label,
|
|
2600
|
-
|
|
2600
|
+
scale=scale, **alt_form
|
|
2601
2601
|
)
|
|
2602
2602
|
elif ftype == 'r':
|
|
2603
2603
|
value = self.render(
|
|
2604
2604
|
form='si', prec=prec, show_units=False, show_label=label,
|
|
2605
|
-
|
|
2605
|
+
scale=scale, **alt_form
|
|
2606
2606
|
)
|
|
2607
2607
|
elif ftype == 'p':
|
|
2608
2608
|
value = self.fixed(
|
|
2609
2609
|
prec=prec, show_units=True, show_label=label,
|
|
2610
|
-
show_commas=bool(comma),
|
|
2611
|
-
strip_radix=not alt_form, scale=scale
|
|
2610
|
+
show_commas=bool(comma), scale=scale, **alt_form
|
|
2612
2611
|
)
|
|
2613
2612
|
elif ftype == 'b':
|
|
2614
2613
|
value = self.binary(
|
|
2615
2614
|
prec=prec, show_units=True, show_label=label,
|
|
2616
|
-
|
|
2617
|
-
scale=scale
|
|
2615
|
+
scale=scale, **alt_form
|
|
2618
2616
|
)
|
|
2619
2617
|
else:
|
|
2620
2618
|
if prec is None:
|
|
@@ -3425,7 +3423,7 @@ class UnitConversion(object):
|
|
|
3425
3423
|
elif from_units in self.to_units and value.units in self.to_units:
|
|
3426
3424
|
pass
|
|
3427
3425
|
else:
|
|
3428
|
-
raise IncompatibleUnits(value
|
|
3426
|
+
raise IncompatibleUnits(value, from_units)
|
|
3429
3427
|
|
|
3430
3428
|
if to_units is None and from_units is None:
|
|
3431
3429
|
to_units = self.to_units[0]
|
|
@@ -3773,4 +3771,3 @@ def binary(value, units, params=None, *args, **kwargs):
|
|
|
3773
3771
|
|
|
3774
3772
|
"""
|
|
3775
3773
|
return Quantity(value, units=units, params=params).binary(*args, **kwargs)
|
|
3776
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|