[yt-svn] commit/yt: MatthewTurk: Merged in ngoldbaum/yt (pull request #1244)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Oct 10 03:23:29 PDT 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/88b61bedaddf/
Changeset:   88b61bedaddf
Branch:      yt
User:        MatthewTurk
Date:        2014-10-10 10:23:16+00:00
Summary:     Merged in ngoldbaum/yt (pull request #1244)

Remove some unnecessary error handling code from YTArray.
Affected #:  1 file

diff -r 047649b328179cc900ab38f3400390e440530ac1 -r 88b61bedaddf676bf3499a6c52e4a14aa28e1ee9 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -44,29 +44,6 @@
     except: return False
     return True
 
-def ensure_unitless(func):
-    @wraps(func)
-    def wrapped(unit):
-        if unit != Unit():
-            raise RuntimeError(
-                "This operation is only defined for unitless quantities. "
-                "Received unit (%s)" % unit
-                )
-        return func(unit)
-    return wrapped
-
-def ensure_same_dimensions(func):
-    @wraps(func)
-    def wrapped(unit1, unit2):
-        if unit1 is None and not unit2.is_dimensionless:
-            raise RuntimeError
-        elif unit2 is None and not unit1.is_dimensionless:
-            raise RuntimeError
-        elif unit1.dimensions != unit2.dimensions:
-            raise RuntimeError
-        return func(unit1, unit2)
-    return wrapped
-
 def return_arr(func):
     @wraps(func)
     def wrapped(*args, **kwargs):
@@ -84,7 +61,6 @@
 def multiply_units(unit1, unit2):
     return unit1 * unit2
 
- at ensure_same_dimensions
 def preserve_units(unit1, unit2):
     return unit1
 
@@ -106,15 +82,9 @@
 def return_without_unit(unit):
     return None
 
- at ensure_unitless
-def unitless(unit):
-    return Unit()
-
- at ensure_same_dimensions
 def arctan2_unit(unit1, unit2):
     return Unit()
 
- at ensure_same_dimensions
 def comparison_unit(unit1, unit2):
     return None
 
@@ -979,12 +949,7 @@
             u = getattr(context[1][0], 'units', None)
             if u is None:
                 u = Unit()
-            try:
-                unit = self._ufunc_registry[context[0]](u)
-            # Catch the RuntimeError raised inside of ensure_same_dimensions
-            # Raise YTUnitOperationError up here since we know the context now
-            except RuntimeError:
-                raise YTUnitOperationError(context[0], u)
+            unit = self._ufunc_registry[context[0]](u)
             ret_class = type(self)
         elif context[0] in binary_operators:
             oper1 = coerce_iterable_units(context[1][0])
@@ -1014,12 +979,7 @@
                         raise YTUnitOperationError(context[0], unit1, unit2)
                     else:
                         raise YTUfuncUnitError(context[0], unit1, unit2)
-            try:
-                unit = self._ufunc_registry[context[0]](unit1, unit2)
-            # Catch the RuntimeError raised inside of ensure_same_dimensions
-            # Raise YTUnitOperationError up here since we know the context now
-            except RuntimeError:
-                raise YTUnitOperationError(context[0], unit1, unit2)
+            unit = self._ufunc_registry[context[0]](unit1, unit2)
         else:
             raise RuntimeError("Operation is not defined.")
         if unit is None:

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list