diff options
author | Hernan Grecco <hernan.grecco@gmail.com> | 2014-11-03 17:05:44 -0300 |
---|---|---|
committer | Hernan Grecco <hernan.grecco@gmail.com> | 2014-11-03 17:05:44 -0300 |
commit | 7ae443e8e887823ba5a76587254bf49441b368d6 (patch) | |
tree | 95abaeac55f2c4dc634eb9e7742a466f09d31462 | |
parent | 419d782fa05305cf856348ae96419cdd16a98da4 (diff) | |
download | pint-7ae443e8e887823ba5a76587254bf49441b368d6.tar.gz |
Better error messages on Quantity.__setitem__.
Fix #191
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | pint/quantity.py | 5 |
2 files changed, 8 insertions, 3 deletions
@@ -5,8 +5,10 @@ Pint Changelog 0.6 (unreleased) ---------------- -- Faster conversions through caching and other performance improvements +- Faster conversions through caching and other performance improvements. (Issue #193, thanks MatthieuDartiailh) +- Better error messages on Quantity.__setitem__. + (Issue #191) - Fixed abbreviation of fluid_ounce. (Issue #187, thanks hsoft) - Defined Angstrom symbol. @@ -19,7 +21,7 @@ Pint Changelog (Issue #179, thanks rsking84) - Optimized "get_dimensionality" and "get_base_name". (Issue #166 and #167, thanks jbmohler) -- Renamed ureg.parse_units parameter "to_delta" to "as_delta" to make clear +- Renamed ureg.parse_units parameter "to_delta" to "as_delta" to make clear. that no conversion happens. Accordingly, the parameter/property "default_to_delta" of UnitRegistry was renamed to "default_as_delta". (Issue #158, thanks dalit) diff --git a/pint/quantity.py b/pint/quantity.py index 4e18f83..069fa0b 100644 --- a/pint/quantity.py +++ b/pint/quantity.py @@ -1024,7 +1024,10 @@ class _Quantity(object): if isinstance(factor, self.__class__): if not factor.dimensionless: - raise ValueError + raise DimensionalityError(value, self.units, + extra_msg='. Assign a quantity with the same dimensionality or ' + 'access the magnitude directly as ' + '`obj.magnitude[%s] = %s`' % (key, value)) self._magnitude[key] = factor.magnitude else: self._magnitude[key] = factor |