summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorJules Chéron <jules.cheron@gmail.com>2020-01-21 21:46:40 +0100
committerJules Chéron <jules.cheron@gmail.com>2020-01-21 21:46:40 +0100
commit90bad48e56e6cbbbb146d1abc6f3c95aa40dcf50 (patch)
tree24d05034456c3d5ab5cf985611e18a1324f0f335 /pint
parent59d9d86f9aeef5cc30adcda58ab81fd85361eb88 (diff)
downloadpint-90bad48e56e6cbbbb146d1abc6f3c95aa40dcf50.tar.gz
Fixed #960
- Handles unit in to_compact. - Use same function infer_base_unit on Quantity based on input unit. - Add unit test in test_issues.py
Diffstat (limited to 'pint')
-rw-r--r--pint/quantity.py2
-rw-r--r--pint/testsuite/test_issues.py5
2 files changed, 7 insertions, 0 deletions
diff --git a/pint/quantity.py b/pint/quantity.py
index 09f7aed..051fc84 100644
--- a/pint/quantity.py
+++ b/pint/quantity.py
@@ -689,6 +689,8 @@ class Quantity(PrettyIPython, SharedRegistryObject):
if unit is None:
unit = infer_base_unit(self)
+ else:
+ unit = infer_base_unit(self.__class__(1, unit))
q_base = self.to(unit)
diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py
index cc04e9f..5f42717 100644
--- a/pint/testsuite/test_issues.py
+++ b/pint/testsuite/test_issues.py
@@ -710,6 +710,11 @@ class TestIssues(QuantityTestCase):
with self.assertRaises(AttributeError):
one_blank = 1 * ureg._ # noqa: F841
+ def test_issue960(self):
+ q = (1 * ureg.nanometer).to_compact("micrometer")
+ assert q.units == ureg.nanometer
+ assert q.magnitude == 1
+
try: