Skip to content

Commit

Permalink
Merge pull request #1 from cometbeetle/nov24_update
Browse files Browse the repository at this point in the history
Update branch with upstream changes to Pint (0.24.4)
  • Loading branch information
varchasgopalaswamy authored Nov 10, 2024
2 parents e3fc388 + cbe53e6 commit f942946
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
numpy: [null, "numpy>=1.23,<2.0.0", "numpy>=2.0.0rc1"]
uncertainties: [null, "uncertainties==3.1.6", "uncertainties>=3.1.6,<4.0.0"]
extras: [null]
Expand Down
34 changes: 31 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
Pint Changelog
==============

0.25 (unreleased)
-----------------
0.25.0 (unreleased)
-------------------

- Nothing changed yet


0.24.4 (2024-11-07)
-------------------

- add error for prefixed non multi units (#1998)
- build: typing_extensions version
- build: switch from appdirs to platformdirs
- fix GenericPlainRegistry getattr type (#2045)
- Replace references to the deprecated `UnitRegistry.default_format` (#2058)
- fix: upgrade to flexparser>=0.4, exceptions are no longer dataclasses.
(required for Python 3.13)


0.24.2 (2024-07-28)
-------------------

- Nothing added yet.
- Fix the default behaviour for pint-convert (cli) for importing uncertainties package (PR #2032, Issue #2016)
- Added mu and mc as alternatives for SI micro prefix
- Added ℓ as alternative for liter
- Support permille units and `‰` symbol (PR #2033, Issue #1963)
- Switch from appdirs to platformdirs.
- Fixes issues related to GenericPlainRegistry.__getattr__ type (PR #2038, Issues #1946 and #1804)
- Removed deprecated references in documentation and tests (PR #2058, Issue #2057)


0.24.1 (2024-06-24)
Expand All @@ -29,6 +53,8 @@ Pint Changelog
- Add `dim_sort` function to _formatter_helpers.
- Add `dim_order` and `default_sort_func` properties to FullFormatter.
(PR #1926, fixes Issue #1841)
- Minimum version requirement added for typing_extensions>=4.0.0.
(PR #1996)
- Documented packages using pint.
(PR #1960)
- Fixed bug causing operations between arrays of quantity scalars and quantity holding
Expand All @@ -42,6 +68,8 @@ Pint Changelog
(PR #1949)
- Fix unhandled TypeError when auto_reduce_dimensions=True and non_int_type=Decimal
(PR #1853)
- Creating prefixed offset units now raises an error.
(PR #1998)
- Improved error message in `get_dimensionality()` when non existent units are passed.
(PR #1874, Issue #1716)

Expand Down
8 changes: 7 additions & 1 deletion docs/_static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ pre, code {

.sd-card .sd-card-header {
border: none;
color: #150458 !important;
color: #150458;
font-size: var(--pst-font-size-h5);
font-weight: bold;
padding: 2.5rem 0rem 0.5rem 0rem;
}

html[data-theme=dark] {
.sd-card .sd-card-header {
color: #FFF;
}
}
4 changes: 2 additions & 2 deletions docs/advanced/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ If you want to use the default cache folder provided by the OS, use **:auto:**
>>> import pint
>>> ureg = pint.UnitRegistry(cache_folder=":auto:") # doctest: +SKIP
Pint use an included version of appdirs_ to obtain the correct folder,
Pint use an external dependency of platformdirs_ to obtain the correct folder,
for example in macOS is `/Users/<username>/Library/Caches/pint`

In any case, you can check the location of the cache folder.
Expand All @@ -146,5 +146,5 @@ In any case, you can check the location of the cache folder.


.. _`brentq method`: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.brentq.html
.. _appdirs: https://pypi.org/project/appdirs/
.. _platformdirs: https://pypi.org/project/platformdirs
.. _flexcache: https://github.com/hgrecco/flexcache/
27 changes: 15 additions & 12 deletions docs/dev/pint-convert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,39 @@ With the `uncertainties` package, the experimental uncertainty in the physical
constants is considered, and the result is given in compact notation, with the
uncertainty in the last figures in parentheses:

The uncertainty can be enabled with `-U` (by default it is not enabled):

.. code-block:: console
$ pint-convert -p 20 -U Eh eV
1 hartree = 27.211386245988(52) eV
.. code-block:: console
$ pint-convert Eh eV
$ pint-convert -U Eh eV
1 hartree = 27.21138624599(5) eV
The precision is limited by both the maximum number of significant digits (`-p`)
and the maximum number of uncertainty digits (`-u`, 2 by default)::

$ pint-convert -p 20 Eh eV
$ pint-convert -U -p 20 Eh eV
1 hartree = 27.211386245988(52) eV

$ pint-convert -p 20 -u 4 Eh eV
$ pint-convert -U -p 20 -u 4 Eh eV
1 hartree = 27.21138624598847(5207) eV

The uncertainty can be disabled with `-U`):

.. code-block:: console
$ pint-convert -p 20 -U Eh eV
1 hartree = 27.211386245988471444 eV
Correlations between experimental constants are also known, and taken into
account. Use `-C` to disable it:
account if uncertainties `-U` is enabled. Use `-C` to disable it:

.. code-block:: console
$ pint-convert --sys atomic m_p
1 proton_mass = 1836.15267344 m_e
$ pint-convert -U --sys atomic m_p
1 proton_mass = 1836.15267344(11) m_e
$ pint-convert --sys atomic -C m_p
$ pint-convert -U --sys atomic -C m_p
1 proton_mass = 1836.15267344(79) m_e
Again, note that results may differ slightly, usually in the last figure, from
Expand Down
4 changes: 2 additions & 2 deletions docs/getting/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Additionally, you can specify a default format specification:
>>> accel = 1.3 * ureg.parse_units('meter/second**2')
>>> 'The acceleration is {}'.format(accel)
'The acceleration is 1.3 meter / second ** 2'
>>> ureg.default_format = 'P'
>>> ureg.formatter.default_format = 'P'
>>> 'The acceleration is {}'.format(accel)
'The acceleration is 1.3 meter/second²'

Expand Down Expand Up @@ -446,7 +446,7 @@ and by doing that, string formatting is now localized:

.. doctest::

>>> ureg.default_format = 'P'
>>> ureg.formatter.default_format = 'P'
>>> accel = 1.3 * ureg.parse_units('meter/second**2')
>>> str(accel)
'1,3 mètres par seconde²'
Expand Down
2 changes: 1 addition & 1 deletion docs/user/nonmult.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For example, to convert from celsius to fahrenheit:

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> ureg.default_format = '.3f'
>>> ureg.formatter.default_format = '.3f'
>>> Q_ = ureg.Quantity
>>> home = Q_(25.4, ureg.degC)
>>> print(home.to('degF'))
Expand Down
7 changes: 6 additions & 1 deletion pint/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class BehaviorChangeWarning(UserWarning):

try:
from uncertainties import UFloat, ufloat
from uncertainties import unumpy as unp

unp = None

HAS_UNCERTAINTIES = True
except ImportError:
Expand All @@ -92,6 +93,8 @@ class BehaviorChangeWarning(UserWarning):
HAS_NUMPY = True
NUMPY_VER = np.__version__
if HAS_UNCERTAINTIES:
from uncertainties import unumpy as unp

NUMERIC_TYPES = (Number, Decimal, ndarray, np.number, UFloat)
else:
NUMERIC_TYPES = (Number, Decimal, ndarray, np.number)
Expand Down Expand Up @@ -249,6 +252,8 @@ class Uncertainty(object):
"xarray.core.variable.Variable",
"pandas.core.series.Series",
"pandas.core.frame.DataFrame",
"pandas.Series",
"pandas.DataFrame",
"xarray.core.dataarray.DataArray",
)

Expand Down
5 changes: 3 additions & 2 deletions pint/default_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pico- = 1e-12 = p-
nano- = 1e-9 = n-
# The micro (U+00B5) and Greek mu (U+03BC) are both valid prefixes,
# and they often use the same glyph.
micro- = 1e-6 = µ- = μ- = u-
micro- = 1e-6 = µ- = μ- = u- = mu- = mc-
milli- = 1e-3 = m-
centi- = 1e-2 = c-
deci- = 1e-1 = d-
Expand Down Expand Up @@ -150,6 +150,7 @@ byte = 8 * bit = B = octet

# Ratios
percent = 0.01 = %
permille = 0.001 = ‰
ppm = 1e-6

# Length
Expand Down Expand Up @@ -221,7 +222,7 @@ hectare = 100 * are = ha

# Volume
[volume] = [length] ** 3
liter = decimeter ** 3 = l = L = litre
liter = decimeter ** 3 = l = L = ℓ = litre
cubic_centimeter = centimeter ** 3 = cc
lambda = microliter = λ
stere = meter ** 3
Expand Down
9 changes: 6 additions & 3 deletions pint/delegates/txt_defparser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

from __future__ import annotations

from dataclasses import dataclass, field
from dataclasses import dataclass

import flexparser as fp

from ... import errors
from ..base_defparser import ParserConfig


@dataclass(frozen=True)
class DefinitionSyntaxError(errors.DefinitionSyntaxError, fp.ParsingError):
"""A syntax error was found in a definition. Combines:
Expand All @@ -30,7 +29,11 @@ class DefinitionSyntaxError(errors.DefinitionSyntaxError, fp.ParsingError):
and an extra location attribute in which the filename or reseource is stored.
"""

location: str = field(init=False, default="")
msg: str

def __init__(self, msg: str, location: str = ""):
self.msg = msg
self.location = location

def __str__(self) -> str:
msg = (
Expand Down
Loading

0 comments on commit f942946

Please sign in to comment.