Skip to content

Commit

Permalink
Merge branch 'master' into issue1949
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage authored May 12, 2024
2 parents 076a5bb + 2b4a8b7 commit ba18610
Show file tree
Hide file tree
Showing 120 changed files with 1,536 additions and 3,793 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.11"
python-version: "3.12"

- name: Install dependencies
run: pip install "numpy>=1.21,<2.0.0"
run: pip install "numpy>=1.23,<2.0.0"

- name: Install bench dependencies
run: pip install .[bench]
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.21,<2.0.0"]
python-version: ["3.10", "3.11", "3.12"]
numpy: [null, "numpy>=1.23,<2.0.0"]
uncertainties: [null, "uncertainties==3.1.6", "uncertainties>=3.1.6,<4.0.0"]
extras: [null]
include:
- python-version: 3.9 # Minimal versions
- python-version: "3.10" # Minimal versions
numpy: "numpy"
extras: matplotlib==2.2.5
- python-version: 3.9
- python-version: "3.10"
numpy: "numpy"
uncertainties: "uncertainties"
extras: "sparse xarray netCDF4 dask[complete]==2023.4.0 graphviz babel==2.8 mip>=1.13"
Expand Down Expand Up @@ -100,8 +100,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11"]
numpy: [ "numpy>=1.21,<2.0.0" ]
python-version: ["3.10", "3.11", "3.12"]
numpy: [ "numpy>=1.23,<2.0.0" ]
runs-on: windows-latest

env:
Expand Down Expand Up @@ -161,8 +161,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.21,<2.0.0" ]
python-version: ["3.10", "3.11", "3.12"]
numpy: [null, "numpy>=1.23,<2.0.0" ]
runs-on: macos-latest

env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up minimal Python version
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"

- name: Get pip cache dir
id: pip-cache
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ MANIFEST
.mypy_cache
pip-wheel-metadata
pint/testsuite/dask-worker-space
venv
.envrc

# WebDAV file system cache files
.DAV/
Expand Down
18 changes: 8 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
exclude: '^pint/_vendor'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.240'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
Expand Down
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Pint Changelog
0.24 (unreleased)
-----------------

- Implement numpy roll (Related to issue #981)
- Add `dim_sort` function to _formatter_helpers.
- Add `dim_order` and `default_sort_func` properties to FullFormatter.
(PR #1926, fixes Issue #1841)
- Fix LaTeX siuntix formatting when using non_int_type=decimal.Decimal.

- Fix converting to offset units of higher dimension e.g. gauge pressure (#1949).
-
Expand Down
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
:target: https://pypi.python.org/pypi/pint
:alt: Latest Version

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/python/black
:target: https://github.com/astral-sh/ruff
:alt: Ruff

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff-Format

.. image:: https://readthedocs.org/projects/pint/badge/
:target: https://pint.readthedocs.org/
Expand Down
6 changes: 4 additions & 2 deletions docs/advanced/pitheorem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ Which can be pretty printed using the `Pint` formatter:

>>> from pint import formatter
>>> result = pi_theorem({'V': '[length]/[time]', 'T': '[time]', 'L': '[length]'})
>>> print(formatter(result[0].items()))
T * V / L
>>> numerator = [item for item in result[0].items() if item[1]>0]
>>> denominator = [item for item in result[0].items() if item[1]<0]
>>> print(formatter(numerator, denominator))
V * T / L

You can also apply the Buckingham π theorem associated to a Registry. In this case,
you can use derived dimensions such as speed:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/facets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The default UnitRegistry inherits from all of them.
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.formatting
.. automodule:: pint.delegates.formatter
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
from __future__ import annotations

import datetime
from importlib.metadata import version
Expand Down
8 changes: 4 additions & 4 deletions docs/getting/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ If Babel_ is installed you can translate unit names to any language
.. doctest::

>>> ureg.formatter.format_quantity(accel, locale='fr_FR')
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'

You can also specify the format locale at the registry level either at creation:

Expand All @@ -449,11 +449,11 @@ and by doing that, string formatting is now localized:
>>> ureg.default_format = 'P'
>>> accel = 1.3 * ureg.parse_units('meter/second**2')
>>> str(accel)
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'
>>> "%s" % accel
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'
>>> "{}".format(accel)
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'

If you want to customize string formatting, take a look at :ref:`formatting`.

Expand Down
37 changes: 34 additions & 3 deletions docs/user/angular_frequency.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
.. _angular_frequency:


Angles and Angular Frequency
=============================

Angles
------

pint treats angle quantities as `dimensionless`, following the conventions of SI. The base unit for angle is the `radian`.
The SI BIPM Brochure (Bureau International des Poids et Mesures) states:

.. note::

Plane and solid angles, when expressed in radians and steradians respectively, are in effect
also treated within the SI as quantities with the unit one (see section 5.4.8). The symbols rad
and sr are written explicitly where appropriate, in order to emphasize that, for radians or
steradians, the quantity being considered is, or involves the plane angle or solid angle
respectively. For steradians it emphasizes the distinction between units of flux and intensity
in radiometry and photometry for example. However, it is a long-established practice in
mathematics and across all areas of science to make use of rad = 1 and sr = 1.


This leads to behavior some users may find unintuitive. For example, since angles have no dimensionality, it is not possible to check whether a quantity has an angle dimension.

.. code-block:: python
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> angle = ureg('1 rad')
>>> angle.dimensionality
<UnitsContainer({})>
Angular Frequency
=================
-----------------

`Hertz` is a unit for frequency, that is often also used for angular frequency. For example, a shaft spinning at `60 revolutions per minute` will often be said to spin at `1 Hz`, rather than `1 revolution per second`.

By default, pint treats angle quantities as `dimensionless`, so allows conversions between frequencies and angular frequencies. The base unit for angle is the `radian`. This leads to some unintuitive behaviour, as pint will convert angular frequencies into frequencies by converting angles into `radians`, rather than `revolutions`. This leads to converted values `2 * pi` larger than expected:
Since pint treats angle quantities as `dimensionless`, it allows conversions between frequencies and angular frequencies. This leads to some unintuitive behaviour, as pint will convert angular frequencies into frequencies by converting angles into `radians`, rather than `revolutions`. This leads to converted values `2 * pi` larger than expected:

.. code-block:: python
Expand All @@ -16,7 +47,7 @@ By default, pint treats angle quantities as `dimensionless`, so allows conversio
>>> angular_frequency.to('Hz')
<Quantity(6.28318531, 'hertz')>
pint follows the conventions of SI. The SI BIPM Brochure (Bureau International des Poids et Mesures) states:
The SI BIPM Brochure (Bureau International des Poids et Mesures) states:

.. note::

Expand Down
2 changes: 1 addition & 1 deletion docs/user/defining-quantities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ For example, the units of
.. doctest::

>>> Q_('3 l / 100 km')
<Quantity(0.03, 'kilometer * liter')>
<Quantity(0.03, 'liter * kilometer')>

may be unexpected at first but, are a consequence of applying this rule. Use
brackets to get the expected result:
Expand Down
5 changes: 3 additions & 2 deletions docs/user/formatting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ formats:
... def format_unit_simple(unit, registry, **options):
... return " * ".join(f"{u} ** {p}" for u, p in unit.items())
>>> f"{q:Z}"
'2.3e-06 meter ** 3 * second ** -2 * kilogram ** -1'
'2.3e-06 kilogram ** -1 * meter ** 3 * second ** -2'

where ``unit`` is a :py:class:`dict` subclass containing the unit names and
their exponents.
Expand All @@ -111,10 +111,11 @@ following methods: `format_magnitude`, `format_unit`, `format_quantity`, `format
...
... default_format = ""
...
... def format_unit(self, unit, uspec: str = "", **babel_kwds) -> str:
... def format_unit(self, unit, uspec, sort_func, **babel_kwds) -> str:
... return "ups!"
...
>>> ureg.formatter = MyFormatter()
>>> ureg.formatter._registry = ureg
>>> str(q)
'2.3e-06 ups!'

Expand Down
2 changes: 2 additions & 0 deletions docs/user/numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"outputs": [],
"source": [
"# Import NumPy\n",
"from __future__ import annotations\n",
"\n",
"import numpy as np\n",
"\n",
"# Import Pint\n",
Expand Down
2 changes: 0 additions & 2 deletions pint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from importlib.metadata import version

from .delegates.formatter._format_helpers import formatter

from .errors import ( # noqa: F401
DefinitionSyntaxError,
DimensionalityError,
Expand All @@ -31,7 +30,6 @@
from .registry import ApplicationRegistry, LazyRegistry, UnitRegistry
from .util import logger, pi_theorem # noqa: F401


# Default Quantity, Unit and Measurement are the ones
# build in the default registry.
Quantity = UnitRegistry.Quantity
Expand Down
5 changes: 3 additions & 2 deletions pint/_typing.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, TypeVar, Union, Protocol
from collections.abc import Callable
from decimal import Decimal
from fractions import Fraction
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union

from .compat import TypeAlias, Never
from .compat import Never, TypeAlias

if TYPE_CHECKING:
from .facets.plain import PlainQuantity as Quantity
Expand Down
Empty file removed pint/_vendor/__init__.py
Empty file.
Loading

0 comments on commit ba18610

Please sign in to comment.