Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Pint Changelog
- 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 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
2 changes: 1 addition & 1 deletion pint/testsuite/test_babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_unit_format_babel():
volume = ureg.Unit("ml")
assert volume.format_babel() == "millilitre"

ureg.default_format = "~"
ureg.formatter.default_format = "~"
assert volume.format_babel() == "ml"

dimensionless_unit = ureg.Unit("")
Expand Down
16 changes: 8 additions & 8 deletions pint/testsuite/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_latex_escaping(self, subtests):
"Lx~": r"\si[]{\%}",
}.items():
with subtests.test(spec):
ureg.default_format = spec
ureg.formatter.default_format = spec
assert f"{x}" == result, f"Failed for {spec}, got {x} expected {result}"
# no '#' here as it's a comment char when define()ing new units
ureg.define(r"weirdunit = 1 = \~_^&%$_{}")
Expand All @@ -83,7 +83,7 @@ def test_latex_escaping(self, subtests):
# "Lx~": r"\si[]{\textbackslash \textasciitilde \_\textasciicircum \&\%\$\_\{\}}",
}.items():
with subtests.test(spec):
ureg.default_format = spec
ureg.formatter.default_format = spec
assert f"{x}" == result, f"Failed for {spec}, {result}"

def test_unit_default_formatting(self, subtests):
Expand All @@ -104,13 +104,13 @@ def test_unit_default_formatting(self, subtests):
("C~", "kg*m**2/s"),
):
with subtests.test(spec):
ureg.default_format = spec
ureg.formatter.default_format = spec
assert f"{x}" == result, f"Failed for {spec}, {result}"

@pytest.mark.xfail(reason="Still not clear how default formatting will work.")
def test_unit_formatting_defaults_warning(self):
ureg = UnitRegistry()
ureg.default_format = "~P"
ureg.formatter.default_format = "~P"
x = ureg.Unit("m / s ** 2")

with pytest.warns(DeprecationWarning):
Expand All @@ -136,7 +136,7 @@ def test_unit_formatting_snake_case(self, subtests):
("C~", "oil_bbl"),
):
with subtests.test(spec):
ureg.default_format = spec
ureg.formatter.default_format = spec
assert f"{x}" == result, f"Failed for {spec}, {result}"

def test_unit_formatting_custom(self, monkeypatch):
Expand Down Expand Up @@ -177,7 +177,7 @@ def pretty(cls, data):
)
x._repr_pretty_(Pretty, False)
assert "".join(alltext) == "kilogram·meter²/second"
ureg.default_format = "~"
ureg.formatter.default_format = "~"
assert x._repr_html_() == "kg m<sup>2</sup>/s"
assert (
x._repr_latex_() == r"$\frac{\mathrm{kg} \cdot \mathrm{m}^{2}}{\mathrm{s}}$"
Expand Down Expand Up @@ -322,11 +322,11 @@ def test_default_format(self):
q = ureg.meter
s1 = f"{q}"
s2 = f"{q:~}"
ureg.default_format = "~"
ureg.formatter.default_format = "~"
s3 = f"{q}"
assert s2 == s3
assert s1 != s3
assert ureg.default_format == "~"
assert ureg.formatter.default_format == "~"

def test_iterate(self):
ureg = UnitRegistry()
Expand Down