summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorHernan Grecco <hgrecco@gmail.com>2023-04-28 19:14:43 -0300
committerHernan Grecco <hgrecco@gmail.com>2023-04-28 19:14:43 -0300
commit7c5bb6cef7b167741f2707e1dc63fbe65a08b0db (patch)
tree8d27add5837808fd3b82670371d41619a0167562 /pint
parent1b54de47fcb3eeaf4c52e5acb519bd212216f413 (diff)
downloadpint-7c5bb6cef7b167741f2707e1dc63fbe65a08b0db.tar.gz
Honor non_int_type when dividing.
Diffstat (limited to 'pint')
-rw-r--r--pint/facets/plain/quantity.py10
-rw-r--r--pint/facets/plain/registry.py6
2 files changed, 13 insertions, 3 deletions
diff --git a/pint/facets/plain/quantity.py b/pint/facets/plain/quantity.py
index f4608c7..22673c8 100644
--- a/pint/facets/plain/quantity.py
+++ b/pint/facets/plain/quantity.py
@@ -1363,6 +1363,14 @@ class PlainQuantity(PrettyIPython, SharedRegistryObject, Generic[_MagnitudeType]
__rmatmul__ = __matmul__
+ def _truedivide_cast_int(self, a, b):
+ t = self._REGISTRY.non_int_type
+ if isinstance(a, int):
+ a = t(a)
+ if isinstance(b, int):
+ b = t(a)
+ return operator.truediv(a, b)
+
def __itruediv__(self, other):
if is_duck_array_type(type(self._magnitude)):
return self._imul_div(other, operator.itruediv)
@@ -1370,6 +1378,8 @@ class PlainQuantity(PrettyIPython, SharedRegistryObject, Generic[_MagnitudeType]
return self._mul_div(other, operator.truediv)
def __truediv__(self, other):
+ if isinstance(self.m, int) or isinstance(getattr(other, "m", None), int):
+ return self._mul_div(other, self._truedivide_cast_int)
return self._mul_div(other, operator.truediv)
def __rtruediv__(self, other):
diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py
index 255c7a5..0bf1545 100644
--- a/pint/facets/plain/registry.py
+++ b/pint/facets/plain/registry.py
@@ -1137,7 +1137,7 @@ class PlainRegistry(metaclass=RegistryMeta):
token_text = token[1]
if token_type == NAME:
if token_text == "dimensionless":
- return self.non_int_type("1") * self.dimensionless
+ return self.Quantity(1, self.dimensionless)
elif token_text.lower() in ("inf", "infinity"):
return self.non_int_type("inf")
elif token_text.lower() == "nan":
@@ -1146,7 +1146,7 @@ class PlainRegistry(metaclass=RegistryMeta):
return self.Quantity(values[token_text])
else:
return self.Quantity(
- self.non_int_type("1"),
+ 1,
self.UnitsContainer(
{self.get_name(token_text, case_sensitive=case_sensitive): 1}
),
@@ -1254,7 +1254,7 @@ class PlainRegistry(metaclass=RegistryMeta):
)
if not input_string:
- return self.Quantity(self.non_int_type("1"))
+ return self.Quantity(1)
for p in self.preprocessors:
input_string = p(input_string)