Skip to content

Commit

Permalink
feat: correct pluralization of localized units
Browse files Browse the repository at this point in the history
This commits involves a heavy refactoring of the helper function for
the formatter. Briefly, before the same function that was generating
the string was splitting beween numerator and denominator. Now this
is done before to allow for correct pluralization.
  • Loading branch information
hgrecco committed Mar 11, 2024
1 parent cbe8077 commit a023056
Show file tree
Hide file tree
Showing 14 changed files with 768 additions and 471 deletions.
53 changes: 27 additions & 26 deletions pint/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@
from decimal import Decimal
from importlib import import_module
from numbers import Number
from typing import Any, NoReturn

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

HAS_UNCERTAINTIES = True
except ImportError:
UFloat = ufloat = unp = None
HAS_UNCERTAINTIES = False


from typing import TypeAlias # noqa

from typing import (
Any,
NoReturn,
TypeAlias, # noqa
)

if sys.version_info >= (3, 11):
from typing import Self # noqa
Expand Down Expand Up @@ -78,6 +69,17 @@ class BehaviorChangeWarning(UserWarning):
pass


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

HAS_UNCERTAINTIES = True
except ImportError:
UFloat = ufloat = unp = None

HAS_UNCERTAINTIES = False


try:
import numpy as np
from numpy import datetime64 as np_datetime64
Expand Down Expand Up @@ -172,6 +174,9 @@ def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
except ImportError:
HAS_BABEL = False

babel_parse = missing_dependency("Babel") # noqa: F811 # type:ignore
babel_units = babel_parse

try:
import mip

Expand All @@ -186,6 +191,14 @@ def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
except ImportError:
HAS_MIP = False

mip_missing = missing_dependency("mip")
mip_model = mip_missing
mip_Model = mip_missing
mip_INF = mip_missing
mip_INTEGER = mip_missing
mip_xsum = mip_missing
mip_OptimizationStatus = mip_missing

# Defines Logarithm and Exponential for Logarithmic Converter
if HAS_NUMPY:
from numpy import (
Expand All @@ -198,18 +211,6 @@ def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
log, # noqa: F401
)

if not HAS_BABEL:
babel_parse = missing_dependency("Babel") # noqa: F811
babel_units = babel_parse

if not HAS_MIP:
mip_missing = missing_dependency("mip")
mip_model = mip_missing
mip_Model = mip_missing
mip_INF = mip_missing
mip_INTEGER = mip_missing
mip_xsum = mip_missing
mip_OptimizationStatus = mip_missing

# Define location of pint.Quantity in NEP-13 type cast hierarchy by defining upcast
# types using guarded imports
Expand Down
Loading

0 comments on commit a023056

Please sign in to comment.