[yt-svn] commit/yt: 3 new changesets

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


3 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/3b28f89b9429/
Changeset:   3b28f89b9429
Branch:      yt
User:        ngoldbaum
Date:        2014-10-08 21:29:36+00:00
Summary:     Remove some unnecessary error handling code from YTArray.

The ensure_same_dimensions function was originally added to ensure that
we are only doing unit operations between quantities that have the same
dimension.

In the meantime, additional error detection code was added in sanitize_units_add
and sanitize_units_mul for the __add__ and __mul__ magic functions and friends.
For ufuncs, which short-circuity magic functions, we test explicitly for
identical units in binary operations.  This means that while
ensure_same_dimensions *was* being called, it never actually raised an error
because the input had already been validated elsewhere.

This patch removes ensure_same_dimensions since it does no useful work. It also
eliminates a place where we catch a generic RuntimeError. This was parituclarly
pernicious in the case of an infinite recursion error, since python raises that
error as a RuntimeError.
Affected #:  1 file

diff -r 7ae8714f591e4c724f7f635bcddb2377cf20b5b3 -r 3b28f89b94295757b1eff53bee32c7d2b36e36b1 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -55,18 +55,6 @@
         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 +72,6 @@
 def multiply_units(unit1, unit2):
     return unit1 * unit2
 
- at ensure_same_dimensions
 def preserve_units(unit1, unit2):
     return unit1
 
@@ -110,11 +97,9 @@
 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 +964,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 +994,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:


https://bitbucket.org/yt_analysis/yt/commits/d7c6d9997d35/
Changeset:   d7c6d9997d35
Branch:      yt
User:        ngoldbaum
Date:        2014-10-08 21:49:37+00:00
Summary:     Removing a bit more dead code in YTArray.
Affected #:  1 file

diff -r 3b28f89b94295757b1eff53bee32c7d2b36e36b1 -r d7c6d9997d356fdb2d27da63cb7b393f0e4f862a yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -44,17 +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 return_arr(func):
     @wraps(func)
     def wrapped(*args, **kwargs):
@@ -93,10 +82,6 @@
 def return_without_unit(unit):
     return None
 
- at ensure_unitless
-def unitless(unit):
-    return Unit()
-
 def arctan2_unit(unit1, unit2):
     return Unit()
 


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