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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Apr 23 06:35:23 PDT 2014


9 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/a6d2ea47b7b0/
Changeset:   a6d2ea47b7b0
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 07:22:26
Summary:     Ensure binary operations preserve unit registries.  Closes #834.
Affected #:  1 file

diff -r e194bdae23c0d3ba246f4ea81d915cf8383e7fe3 -r a6d2ea47b7b000c9f4484eb5472e52cee6e85a03 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -775,9 +775,9 @@
             unit1 = getattr(context[1][0], 'units', None)
             unit2 = getattr(context[1][1], 'units', None)
             if unit1 == None:
-                unit1 = Unit()
+                unit1 = Unit(registry=unit2.registry)
             if unit2 == None and context[0] is not power:
-                unit2 = Unit()
+                unit2 = Unit(registry=unit1.registry)
             elif context[0] is power:
                 unit2 = context[1][1]
                 if isinstance(unit2, np.ndarray):


https://bitbucket.org/yt_analysis/yt/commits/97e254ca2ee4/
Changeset:   97e254ca2ee4
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 08:25:54
Summary:     Both units will sometimes be None.  Deal with this.

Due to details of how ndarray subclasses are implemented inside numpy,
specifically the way pretty printing works, we will sometimes get to this point
in the code without ever actually setting a unit for either object, even though
one of them is a YTArray.  This deals with that situation while still preserving
the nice behavior of keeping the correct unit registry around.
Affected #:  1 file

diff -r a6d2ea47b7b000c9f4484eb5472e52cee6e85a03 -r 97e254ca2ee455ec3f8a0f2b056d8003be86a050 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -774,10 +774,10 @@
         elif context[0] in binary_operators:
             unit1 = getattr(context[1][0], 'units', None)
             unit2 = getattr(context[1][1], 'units', None)
-            if unit1 == None:
-                unit1 = Unit(registry=unit2.registry)
-            if unit2 == None and context[0] is not power:
-                unit2 = Unit(registry=unit1.registry)
+            if unit1 is None:
+                unit1 = Unit(registry=getattr(unit2, 'registry', None))
+            if unit2 is None and context[0] is not power:
+                unit2 = Unit(registry=getattr(unit1, 'registry', None))
             elif context[0] is power:
                 unit2 = context[1][1]
                 if isinstance(unit2, np.ndarray):


https://bitbucket.org/yt_analysis/yt/commits/05d9c4e9f6fc/
Changeset:   05d9c4e9f6fc
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 10:11:40
Summary:     Fixing a bug in isub found by flake8.

This may have caused subtle buggyness when using the -= operator on arrays with
different units.  Yay flake8!
Affected #:  1 file

diff -r 97e254ca2ee455ec3f8a0f2b056d8003be86a050 -r 05d9c4e9f6fcbd5578ed9c8764366b1a946f29c1 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -497,7 +497,7 @@
     def __isub__(self, other):
         """ See __sub__. """
         oth = sanitize_units_add(self, other, "subtraction")
-        return np.subtract(self, other, out=self)
+        return np.subtract(self, oth, out=self)
 
     def __neg__(self):
         """ Negate the data. """


https://bitbucket.org/yt_analysis/yt/commits/5d2b48ca9e3f/
Changeset:   5d2b48ca9e3f
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 10:12:06
Summary:     Adding a __pos__ magic function override for YTArray.
Affected #:  1 file

diff -r 05d9c4e9f6fcbd5578ed9c8764366b1a946f29c1 -r 5d2b48ca9e3f4939d5b1dd6f2b994d2a10374ad5 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -503,6 +503,10 @@
         """ Negate the data. """
         return YTArray(super(YTArray, self).__neg__())
 
+    def __pos__(self):
+        """ Posify the data. """
+        return YTArray(super(YTArray, self).__pos__())
+
     def __mul__(self, right_object):
         """
         Multiply this YTArray by the object on the right of the `*` operator.


https://bitbucket.org/yt_analysis/yt/commits/289afe0300b9/
Changeset:   289afe0300b9
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 10:12:17
Summary:     Fixing minor linting issues.
Affected #:  1 file

diff -r 5d2b48ca9e3f4939d5b1dd6f2b994d2a10374ad5 -r 289afe0300b9589a52adf700bd62a07fabbf499c yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -669,7 +669,7 @@
     def __eq__(self, other):
         """ Test if this is equal to the object on the right. """
         # Check that other is a YTArray.
-        if other == None:
+        if other is None:
             # self is a YTArray, so it can't be None.
             return False
         if isinstance(other, YTArray):
@@ -683,7 +683,7 @@
     def __ne__(self, other):
         """ Test if this is not equal to the object on the right. """
         # Check that the other is a YTArray.
-        if other == None:
+        if other is None:
             return True
         if isinstance(other, YTArray):
             if not self.units.same_dimensions_as(other.units):
@@ -767,7 +767,7 @@
                 return ret
         elif context[0] in unary_operators:
             u = getattr(context[1][0], 'units', None)
-            if u == None:
+            if u is None:
                 u = Unit()
             try:
                 unit = self._ufunc_registry[context[0]](u)
@@ -821,8 +821,8 @@
         See the documentation for the standard library pickle module:
         http://docs.python.org/2/library/pickle.html
 
-        Unit metadata is encoded in the zeroth element of third element of the 
-        returned tuple, itself a tuple used to restore the state of the ndarray.  
+        Unit metadata is encoded in the zeroth element of third element of the
+        returned tuple, itself a tuple used to restore the state of the ndarray.
         This is always defined for numpy arrays.
         """
         np_ret = super(YTArray, self).__reduce__()


https://bitbucket.org/yt_analysis/yt/commits/12438aa6dc05/
Changeset:   12438aa6dc05
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 10:12:36
Summary:     Adding tests for unit registry association under various operators.
Affected #:  1 file

diff -r 289afe0300b9589a52adf700bd62a07fabbf499c -r 12438aa6dc050acdba0d76d67a8e48ce8ca46e51 yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -592,3 +592,32 @@
 
     yield assert_array_equal, arr.value, np.array(arr)
     yield assert_array_equal, arr.v, np.array(arr)
+
+
+def test_registry_association():
+    ds = fake_random_pf(64, nprocs=1, length_unit=10)
+    a = ds.quan(3, 'cm')
+    b = YTQuantity(4, 'm')
+
+    yield assert_equal, id(a.units.registry), id(ds.unit_registry)
+
+    def binary_op_registry_comparison(op):
+        c = op(a, b)
+        d = op(b, a)
+
+        assert_equal(id(c.units.registry), id(ds.unit_registry))
+        assert_equal(id(d.units.registry), id(b.units.registry))
+
+    def unary_op_registry_comparison(op):
+        c = op(a)
+        d = op(b)
+
+        assert_equal(id(c.units.registry), id(ds.unit_registry))
+        assert_equal(id(d.units.registry), id(b.units.registry))
+
+    for op in [operator.add, operator.sub, operator.mul, operator.div,
+               operator.truediv]:
+        yield binary_op_registry_comparison, op
+
+    for op in [operator.abs, operator.neg, operator.pos]:
+        yield unary_op_registry_comparison, op


https://bitbucket.org/yt_analysis/yt/commits/6a70249d47e7/
Changeset:   6a70249d47e7
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 10:42:14
Summary:     Need to explicitly apply units for pos since there is no ufunc for it.
Affected #:  1 file

diff -r 12438aa6dc050acdba0d76d67a8e48ce8ca46e51 -r 6a70249d47e746aaafa0579d8b6080c8a2831538 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -505,7 +505,7 @@
 
     def __pos__(self):
         """ Posify the data. """
-        return YTArray(super(YTArray, self).__pos__())
+        return YTArray(super(YTArray, self).__pos__(), self.units)
 
     def __mul__(self, right_object):
         """


https://bitbucket.org/yt_analysis/yt/commits/e4942fc95da3/
Changeset:   e4942fc95da3
Branch:      yt-3.0
User:        ngoldbaum
Date:        2014-04-23 10:57:56
Summary:     Adding more unit registry association tests.
Affected #:  1 file

diff -r 6a70249d47e746aaafa0579d8b6080c8a2831538 -r e4942fc95da33a87b4818d3d64d0f3d2f42e4f5d yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -598,15 +598,21 @@
     ds = fake_random_pf(64, nprocs=1, length_unit=10)
     a = ds.quan(3, 'cm')
     b = YTQuantity(4, 'm')
+    c = ds.quan(6, '')
+    d = 5
 
     yield assert_equal, id(a.units.registry), id(ds.unit_registry)
 
     def binary_op_registry_comparison(op):
-        c = op(a, b)
-        d = op(b, a)
+        e = op(a, b)
+        f = op(b, a)
+        g = op(c, d)
+        h = op(d, c)
 
-        assert_equal(id(c.units.registry), id(ds.unit_registry))
-        assert_equal(id(d.units.registry), id(b.units.registry))
+        assert_equal(id(e.units.registry), id(ds.unit_registry))
+        assert_equal(id(f.units.registry), id(b.units.registry))
+        assert_equal(id(g.units.registry), id(h.units.registry))
+        assert_equal(id(g.units.registry), id(ds.unit_registry))
 
     def unary_op_registry_comparison(op):
         c = op(a)


https://bitbucket.org/yt_analysis/yt/commits/2dd2d810e60c/
Changeset:   2dd2d810e60c
Branch:      yt-3.0
User:        jzuhone
Date:        2014-04-23 15:35:12
Summary:     Merged in ngoldbaum/yt/yt-3.0 (pull request #848)

Ensure binary operations preserve unit registries.  Closes #834.
Affected #:  2 files

diff -r f0dcca6509b72331853fd900470a8ed10275cd62 -r 2dd2d810e60cebaaab21688cf06e69580a3ad76d yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -592,3 +592,38 @@
 
     yield assert_array_equal, arr.value, np.array(arr)
     yield assert_array_equal, arr.v, np.array(arr)
+
+
+def test_registry_association():
+    ds = fake_random_pf(64, nprocs=1, length_unit=10)
+    a = ds.quan(3, 'cm')
+    b = YTQuantity(4, 'm')
+    c = ds.quan(6, '')
+    d = 5
+
+    yield assert_equal, id(a.units.registry), id(ds.unit_registry)
+
+    def binary_op_registry_comparison(op):
+        e = op(a, b)
+        f = op(b, a)
+        g = op(c, d)
+        h = op(d, c)
+
+        assert_equal(id(e.units.registry), id(ds.unit_registry))
+        assert_equal(id(f.units.registry), id(b.units.registry))
+        assert_equal(id(g.units.registry), id(h.units.registry))
+        assert_equal(id(g.units.registry), id(ds.unit_registry))
+
+    def unary_op_registry_comparison(op):
+        c = op(a)
+        d = op(b)
+
+        assert_equal(id(c.units.registry), id(ds.unit_registry))
+        assert_equal(id(d.units.registry), id(b.units.registry))
+
+    for op in [operator.add, operator.sub, operator.mul, operator.div,
+               operator.truediv]:
+        yield binary_op_registry_comparison, op
+
+    for op in [operator.abs, operator.neg, operator.pos]:
+        yield unary_op_registry_comparison, op

diff -r f0dcca6509b72331853fd900470a8ed10275cd62 -r 2dd2d810e60cebaaab21688cf06e69580a3ad76d yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -497,12 +497,16 @@
     def __isub__(self, other):
         """ See __sub__. """
         oth = sanitize_units_add(self, other, "subtraction")
-        return np.subtract(self, other, out=self)
+        return np.subtract(self, oth, out=self)
 
     def __neg__(self):
         """ Negate the data. """
         return YTArray(super(YTArray, self).__neg__())
 
+    def __pos__(self):
+        """ Posify the data. """
+        return YTArray(super(YTArray, self).__pos__(), self.units)
+
     def __mul__(self, right_object):
         """
         Multiply this YTArray by the object on the right of the `*` operator.
@@ -665,7 +669,7 @@
     def __eq__(self, other):
         """ Test if this is equal to the object on the right. """
         # Check that other is a YTArray.
-        if other == None:
+        if other is None:
             # self is a YTArray, so it can't be None.
             return False
         if isinstance(other, YTArray):
@@ -679,7 +683,7 @@
     def __ne__(self, other):
         """ Test if this is not equal to the object on the right. """
         # Check that the other is a YTArray.
-        if other == None:
+        if other is None:
             return True
         if isinstance(other, YTArray):
             if not self.units.same_dimensions_as(other.units):
@@ -763,7 +767,7 @@
                 return ret
         elif context[0] in unary_operators:
             u = getattr(context[1][0], 'units', None)
-            if u == None:
+            if u is None:
                 u = Unit()
             try:
                 unit = self._ufunc_registry[context[0]](u)
@@ -774,10 +778,10 @@
         elif context[0] in binary_operators:
             unit1 = getattr(context[1][0], 'units', None)
             unit2 = getattr(context[1][1], 'units', None)
-            if unit1 == None:
-                unit1 = Unit()
-            if unit2 == None and context[0] is not power:
-                unit2 = Unit()
+            if unit1 is None:
+                unit1 = Unit(registry=getattr(unit2, 'registry', None))
+            if unit2 is None and context[0] is not power:
+                unit2 = Unit(registry=getattr(unit1, 'registry', None))
             elif context[0] is power:
                 unit2 = context[1][1]
                 if isinstance(unit2, np.ndarray):
@@ -817,8 +821,8 @@
         See the documentation for the standard library pickle module:
         http://docs.python.org/2/library/pickle.html
 
-        Unit metadata is encoded in the zeroth element of third element of the 
-        returned tuple, itself a tuple used to restore the state of the ndarray.  
+        Unit metadata is encoded in the zeroth element of third element of the
+        returned tuple, itself a tuple used to restore the state of the ndarray.
         This is always defined for numpy arrays.
         """
         np_ret = super(YTArray, self).__reduce__()

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