Skip to content

Commit

Permalink
Updated CHANGES to new exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Dec 28, 2019
1 parent 3a582af commit 8c82eae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Pint Changelog
0.10 (unreleased)
-----------------

- Improvements to wraps and check:
- fail upon decoration (not execution) by checking wrapped function signature against
wraps/check arguments.
(might BREAK test code)
- wraps only accepts strings and Units (not quantities) to avoid confusion with magnitude.
(might BREAK code not conforming to documentation)
- when strict=True, strings that can be parsed to quantities are accepted as arguments.
- Add revolutions per second (rps)
- Improved compatbility for upcast types like xarray's DataArray or Dataset, to which
Pint Quantities now fully defer for arithmetic and NumPy operations. A collection of
Expand Down
26 changes: 15 additions & 11 deletions pint/testsuite/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ def func(x):

ureg = self.ureg

self.assertRaises(TypeError, ureg.wraps, (3 * ureg.meter, [None]))
self.assertRaises(TypeError, ureg.wraps, (None, [3 * ureg.meter]))

f0 = ureg.wraps(None, [None])(func)
self.assertEqual(f0(3.0), 3.0)

Expand All @@ -451,6 +454,16 @@ def func(x):
self.assertEqual(f1b(3.0 * ureg.meter), 3.0)
self.assertRaises(DimensionalityError, f1b, 3 * ureg.second)

f1c = ureg.wraps("meter", [ureg.meter])(func)
self.assertEqual(f1c(3.0 * ureg.centimeter), 0.03 * ureg.meter)
self.assertEqual(f1c(3.0 * ureg.meter), 3.0 * ureg.meter)
self.assertRaises(DimensionalityError, f1c, 3 * ureg.second)

f1d = ureg.wraps(ureg.meter, [ureg.meter])(func)
self.assertEqual(f1d(3.0 * ureg.centimeter), 0.03 * ureg.meter)
self.assertEqual(f1d(3.0 * ureg.meter), 3.0 * ureg.meter)
self.assertRaises(DimensionalityError, f1d, 3 * ureg.second)

f1 = ureg.wraps(None, "meter")(func)
self.assertRaises(ValueError, f1, 3.0)
self.assertEqual(f1(3.0 * ureg.centimeter), 0.03)
Expand Down Expand Up @@ -565,17 +578,8 @@ def gfunc(x, y):
1 * ureg.meter / ureg.second ** 2,
)

g2 = ureg.check("[speed]")(gfunc)
self.assertRaises(DimensionalityError, g2, 3.0, 1)
self.assertRaises(TypeError, g2, 2 * ureg.parsec)
self.assertRaises(DimensionalityError, g2, 2 * ureg.parsec, 1.0)
self.assertEqual(g2(2.0 * ureg.km / ureg.hour, 2), 1 * ureg.km / ureg.hour)

g3 = ureg.check("[speed]", "[time]", "[mass]")(gfunc)
self.assertRaises(TypeError, g3, 1 * ureg.parsec, 1 * ureg.angstrom)
self.assertRaises(
TypeError, g3, 1 * ureg.parsec, 1 * ureg.angstrom, 1 * ureg.kilogram
)
self.assertRaises(TypeError, ureg.check("[speed]"), gfunc)
self.assertRaises(TypeError, ureg.check("[speed]", "[time]", "[mass]"), gfunc)

def test_to_ref_vs_to(self):
self.ureg.autoconvert_offset_to_baseunit = True
Expand Down

0 comments on commit 8c82eae

Please sign in to comment.