[yt-svn] commit/yt: 2 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Mar 30 11:27:36 PDT 2016
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/0c1d2aceba78/
Changeset: 0c1d2aceba78
Branch: yt
User: ngoldbaum
Date: 2016-03-25 20:12:59+00:00
Summary: Ensure instances of subclasses of YTArray have the correct type. Closes #1197.
Affected #: 2 files
diff -r a776e67368c5629296b1e365dfca0b68b41ef1d5 -r 0c1d2aceba78e05e78b7d9e85c9022b16e2344f2 yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -541,17 +541,17 @@
a = YTArray(range(10), 'cm')
b = YTQuantity(5, 'g')
- yield assert_isinstance, a*b, YTArray
- yield assert_isinstance, b*a, YTArray
+ assert_isinstance(a*b, YTArray)
+ assert_isinstance(b*a, YTArray)
- yield assert_isinstance, a/b, YTArray
- yield assert_isinstance, b/a, YTArray
+ assert_isinstance(a/b, YTArray)
+ assert_isinstance(b/a, YTArray)
- yield assert_isinstance, a*a, YTArray
- yield assert_isinstance, a/a, YTArray
+ assert_isinstance(a*a, YTArray)
+ assert_isinstance(a/a, YTArray)
- yield assert_isinstance, b*b, YTQuantity
- yield assert_isinstance, b/b, YTQuantity
+ assert_isinstance(b*b, YTQuantity)
+ assert_isinstance(b/b, YTQuantity)
def test_selecting():
@@ -910,21 +910,22 @@
ops.append(operator.div)
for op in ops:
for inst in (b, ytq, ndf, yta, nda, loq):
- yield op_comparison, op, a, inst, YTASubclass
+ op_comparison(op, a, inst, YTASubclass)
- yield op_comparison, op, ytq, nda, YTArray
- yield op_comparison, op, ytq, yta, YTArray
+ op_comparison(op, ytq, nda, YTArray)
+ op_comparison(op, ytq, yta, YTArray)
for op in (operator.add, operator.sub):
- yield op_comparison, op, nu, nda, YTASubclass
- yield op_comparison, op, a, b, YTASubclass
- yield op_comparison, op, a, yta, YTASubclass
- yield op_comparison, op, a, loq, YTASubclass
+ op_comparison(op, nu, nda, YTASubclass)
+ op_comparison(op, a, b, YTASubclass)
+ op_comparison(op, a, yta, YTASubclass)
+ op_comparison(op, a, loq, YTASubclass)
- yield assert_isinstance, a[0], YTQuantity
- yield assert_isinstance, a[:], YTASubclass
- yield assert_isinstance, a[:2], YTASubclass
-
+ assert_isinstance(a[0], YTQuantity)
+ assert_isinstance(a[:], YTASubclass)
+ assert_isinstance(a[:2], YTASubclass)
+ assert_isinstance(YTASubclass(yta), YTASubclass)
+
def test_h5_io():
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
diff -r a776e67368c5629296b1e365dfca0b68b41ef1d5 -r 0c1d2aceba78e05e78b7d9e85c9022b16e2344f2 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -333,7 +333,7 @@
obj.units.registry = registry
return obj
if input_array is NotImplemented:
- return input_array
+ return input_array.view(cls)
if registry is None and isinstance(input_units, (str, bytes)):
if input_units.startswith('code_'):
raise UnitParseError(
@@ -352,7 +352,7 @@
input_array.units = input_units
else:
input_array.units = Unit(input_units, registry=registry)
- return input_array
+ return input_array.view(cls)
elif isinstance(input_array, np.ndarray):
pass
elif iterable(input_array) and input_array:
@@ -885,12 +885,12 @@
"""
ro = sanitize_units_add(self, right_object, "addition")
- return YTArray(super(YTArray, self).__add__(ro))
+ return super(YTArray, self).__add__(ro)
def __radd__(self, left_object):
""" See __add__. """
lo = sanitize_units_add(self, left_object, "addition")
- return YTArray(super(YTArray, self).__radd__(lo))
+ return super(YTArray, self).__radd__(lo)
def __iadd__(self, other):
""" See __add__. """
@@ -905,12 +905,12 @@
"""
ro = sanitize_units_add(self, right_object, "subtraction")
- return YTArray(super(YTArray, self).__sub__(ro))
+ return super(YTArray, self).__sub__(ro)
def __rsub__(self, left_object):
""" See __sub__. """
lo = sanitize_units_add(self, left_object, "subtraction")
- return YTArray(super(YTArray, self).__rsub__(lo))
+ return super(YTArray, self).__rsub__(lo)
def __isub__(self, other):
""" See __sub__. """
@@ -920,11 +920,11 @@
def __neg__(self):
""" Negate the data. """
- return YTArray(super(YTArray, self).__neg__())
+ return super(YTArray, self).__neg__()
def __pos__(self):
""" Posify the data. """
- return YTArray(super(YTArray, self).__pos__(), self.units)
+ return type(self)(super(YTArray, self).__pos__(), self.units)
def __mul__(self, right_object):
"""
@@ -933,12 +933,12 @@
"""
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__mul__(ro))
+ return super(YTArray, self).__mul__(ro)
def __rmul__(self, left_object):
""" See __mul__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rmul__(lo))
+ return super(YTArray, self).__rmul__(lo)
def __imul__(self, other):
""" See __mul__. """
@@ -952,12 +952,12 @@
"""
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__div__(ro))
+ return super(YTArray, self).__div__(ro)
def __rdiv__(self, left_object):
""" See __div__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rdiv__(lo))
+ return super(YTArray, self).__rdiv__(lo)
def __idiv__(self, other):
""" See __div__. """
@@ -967,12 +967,12 @@
def __truediv__(self, right_object):
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__truediv__(ro))
+ return super(YTArray, self).__truediv__(ro)
def __rtruediv__(self, left_object):
""" See __div__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rtruediv__(lo))
+ return super(YTArray, self).__rtruediv__(lo)
def __itruediv__(self, other):
""" See __div__. """
@@ -982,12 +982,12 @@
def __floordiv__(self, right_object):
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__floordiv__(ro))
+ return super(YTArray, self).__floordiv__(ro)
def __rfloordiv__(self, left_object):
""" See __div__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rfloordiv__(lo))
+ return super(YTArray, self).__rfloordiv__(lo)
def __ifloordiv__(self, other):
""" See __div__. """
@@ -995,32 +995,31 @@
np.floor_divide(self, oth, out=self)
return self
- #Should these raise errors? I need to come back and check this.
def __or__(self, right_object):
- return YTArray(super(YTArray, self).__or__(right_object))
+ return super(YTArray, self).__or__(right_object)
def __ror__(self, left_object):
- return YTArray(super(YTArray, self).__ror__(left_object))
+ return super(YTArray, self).__ror__(left_object)
def __ior__(self, other):
np.bitwise_or(self, other, out=self)
return self
def __xor__(self, right_object):
- return YTArray(super(YTArray, self).__xor__(right_object))
+ return super(YTArray, self).__xor__(right_object)
def __rxor__(self, left_object):
- return YTArray(super(YTArray, self).__rxor__(left_object))
+ return super(YTArray, self).__rxor__(left_object)
def __ixor__(self, other):
np.bitwise_xor(self, other, out=self)
return self
def __and__(self, right_object):
- return YTArray(super(YTArray, self).__and__(right_object))
+ return super(YTArray, self).__and__(right_object)
def __rand__(self, left_object):
- return YTArray(super(YTArray, self).__rand__(left_object))
+ return super(YTArray, self).__rand__(left_object)
def __iand__(self, other):
np.bitwise_and(self, other, out=self)
@@ -1047,13 +1046,13 @@
# dimensionless Unit object.
if self.units.is_dimensionless and power == -1:
ret = super(YTArray, self).__pow__(power)
- return YTArray(ret, input_units='')
+ return type(self)(ret, input_units='')
- return YTArray(super(YTArray, self).__pow__(power))
+ return super(YTArray, self).__pow__(power)
def __abs__(self):
""" Return a YTArray with the abs of the data. """
- return YTArray(super(YTArray, self).__abs__())
+ return super(YTArray, self).__abs__()
def sqrt(self):
"""
@@ -1061,18 +1060,17 @@
take the 1/2 power of the units.
"""
- return YTArray(super(YTArray, self).sqrt(),
- input_units=self.units**0.5)
+ return type(self)(super(YTArray, self).sqrt(),
+ input_units=self.units**0.5)
#
# Start comparison operators.
#
- # @todo: outsource to a single method with an op argument.
-
def __lt__(self, other):
""" Test if this is less than the object on the right. """
- oth = validate_comparison_units(self, other, 'less_than') # converts if possible
+ # converts if possible
+ oth = validate_comparison_units(self, other, 'less_than')
return super(YTArray, self).__lt__(oth)
def __le__(self, other):
https://bitbucket.org/yt_analysis/yt/commits/a98dd29e4e93/
Changeset: a98dd29e4e93
Branch: yt
User: xarthisius
Date: 2016-03-30 18:27:25+00:00
Summary: Merged in ngoldbaum/yt (pull request #2083)
Ensure instances of subclasses of YTArray have the correct type. Closes #1197.
Affected #: 2 files
diff -r c9a19dd7d6e63996b30850bf9660203d64e6b5b8 -r a98dd29e4e93fef8002811e9e05e34810574b9cd yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -541,17 +541,17 @@
a = YTArray(range(10), 'cm')
b = YTQuantity(5, 'g')
- yield assert_isinstance, a*b, YTArray
- yield assert_isinstance, b*a, YTArray
+ assert_isinstance(a*b, YTArray)
+ assert_isinstance(b*a, YTArray)
- yield assert_isinstance, a/b, YTArray
- yield assert_isinstance, b/a, YTArray
+ assert_isinstance(a/b, YTArray)
+ assert_isinstance(b/a, YTArray)
- yield assert_isinstance, a*a, YTArray
- yield assert_isinstance, a/a, YTArray
+ assert_isinstance(a*a, YTArray)
+ assert_isinstance(a/a, YTArray)
- yield assert_isinstance, b*b, YTQuantity
- yield assert_isinstance, b/b, YTQuantity
+ assert_isinstance(b*b, YTQuantity)
+ assert_isinstance(b/b, YTQuantity)
def test_selecting():
@@ -910,21 +910,22 @@
ops.append(operator.div)
for op in ops:
for inst in (b, ytq, ndf, yta, nda, loq):
- yield op_comparison, op, a, inst, YTASubclass
+ op_comparison(op, a, inst, YTASubclass)
- yield op_comparison, op, ytq, nda, YTArray
- yield op_comparison, op, ytq, yta, YTArray
+ op_comparison(op, ytq, nda, YTArray)
+ op_comparison(op, ytq, yta, YTArray)
for op in (operator.add, operator.sub):
- yield op_comparison, op, nu, nda, YTASubclass
- yield op_comparison, op, a, b, YTASubclass
- yield op_comparison, op, a, yta, YTASubclass
- yield op_comparison, op, a, loq, YTASubclass
+ op_comparison(op, nu, nda, YTASubclass)
+ op_comparison(op, a, b, YTASubclass)
+ op_comparison(op, a, yta, YTASubclass)
+ op_comparison(op, a, loq, YTASubclass)
- yield assert_isinstance, a[0], YTQuantity
- yield assert_isinstance, a[:], YTASubclass
- yield assert_isinstance, a[:2], YTASubclass
-
+ assert_isinstance(a[0], YTQuantity)
+ assert_isinstance(a[:], YTASubclass)
+ assert_isinstance(a[:2], YTASubclass)
+ assert_isinstance(YTASubclass(yta), YTASubclass)
+
def test_h5_io():
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
diff -r c9a19dd7d6e63996b30850bf9660203d64e6b5b8 -r a98dd29e4e93fef8002811e9e05e34810574b9cd yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -333,7 +333,7 @@
obj.units.registry = registry
return obj
if input_array is NotImplemented:
- return input_array
+ return input_array.view(cls)
if registry is None and isinstance(input_units, (str, bytes)):
if input_units.startswith('code_'):
raise UnitParseError(
@@ -352,7 +352,7 @@
input_array.units = input_units
else:
input_array.units = Unit(input_units, registry=registry)
- return input_array
+ return input_array.view(cls)
elif isinstance(input_array, np.ndarray):
pass
elif iterable(input_array) and input_array:
@@ -885,12 +885,12 @@
"""
ro = sanitize_units_add(self, right_object, "addition")
- return YTArray(super(YTArray, self).__add__(ro))
+ return super(YTArray, self).__add__(ro)
def __radd__(self, left_object):
""" See __add__. """
lo = sanitize_units_add(self, left_object, "addition")
- return YTArray(super(YTArray, self).__radd__(lo))
+ return super(YTArray, self).__radd__(lo)
def __iadd__(self, other):
""" See __add__. """
@@ -905,12 +905,12 @@
"""
ro = sanitize_units_add(self, right_object, "subtraction")
- return YTArray(super(YTArray, self).__sub__(ro))
+ return super(YTArray, self).__sub__(ro)
def __rsub__(self, left_object):
""" See __sub__. """
lo = sanitize_units_add(self, left_object, "subtraction")
- return YTArray(super(YTArray, self).__rsub__(lo))
+ return super(YTArray, self).__rsub__(lo)
def __isub__(self, other):
""" See __sub__. """
@@ -920,11 +920,11 @@
def __neg__(self):
""" Negate the data. """
- return YTArray(super(YTArray, self).__neg__())
+ return super(YTArray, self).__neg__()
def __pos__(self):
""" Posify the data. """
- return YTArray(super(YTArray, self).__pos__(), self.units)
+ return type(self)(super(YTArray, self).__pos__(), self.units)
def __mul__(self, right_object):
"""
@@ -933,12 +933,12 @@
"""
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__mul__(ro))
+ return super(YTArray, self).__mul__(ro)
def __rmul__(self, left_object):
""" See __mul__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rmul__(lo))
+ return super(YTArray, self).__rmul__(lo)
def __imul__(self, other):
""" See __mul__. """
@@ -952,12 +952,12 @@
"""
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__div__(ro))
+ return super(YTArray, self).__div__(ro)
def __rdiv__(self, left_object):
""" See __div__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rdiv__(lo))
+ return super(YTArray, self).__rdiv__(lo)
def __idiv__(self, other):
""" See __div__. """
@@ -967,12 +967,12 @@
def __truediv__(self, right_object):
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__truediv__(ro))
+ return super(YTArray, self).__truediv__(ro)
def __rtruediv__(self, left_object):
""" See __div__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rtruediv__(lo))
+ return super(YTArray, self).__rtruediv__(lo)
def __itruediv__(self, other):
""" See __div__. """
@@ -982,12 +982,12 @@
def __floordiv__(self, right_object):
ro = sanitize_units_mul(self, right_object)
- return YTArray(super(YTArray, self).__floordiv__(ro))
+ return super(YTArray, self).__floordiv__(ro)
def __rfloordiv__(self, left_object):
""" See __div__. """
lo = sanitize_units_mul(self, left_object)
- return YTArray(super(YTArray, self).__rfloordiv__(lo))
+ return super(YTArray, self).__rfloordiv__(lo)
def __ifloordiv__(self, other):
""" See __div__. """
@@ -995,32 +995,31 @@
np.floor_divide(self, oth, out=self)
return self
- #Should these raise errors? I need to come back and check this.
def __or__(self, right_object):
- return YTArray(super(YTArray, self).__or__(right_object))
+ return super(YTArray, self).__or__(right_object)
def __ror__(self, left_object):
- return YTArray(super(YTArray, self).__ror__(left_object))
+ return super(YTArray, self).__ror__(left_object)
def __ior__(self, other):
np.bitwise_or(self, other, out=self)
return self
def __xor__(self, right_object):
- return YTArray(super(YTArray, self).__xor__(right_object))
+ return super(YTArray, self).__xor__(right_object)
def __rxor__(self, left_object):
- return YTArray(super(YTArray, self).__rxor__(left_object))
+ return super(YTArray, self).__rxor__(left_object)
def __ixor__(self, other):
np.bitwise_xor(self, other, out=self)
return self
def __and__(self, right_object):
- return YTArray(super(YTArray, self).__and__(right_object))
+ return super(YTArray, self).__and__(right_object)
def __rand__(self, left_object):
- return YTArray(super(YTArray, self).__rand__(left_object))
+ return super(YTArray, self).__rand__(left_object)
def __iand__(self, other):
np.bitwise_and(self, other, out=self)
@@ -1047,13 +1046,13 @@
# dimensionless Unit object.
if self.units.is_dimensionless and power == -1:
ret = super(YTArray, self).__pow__(power)
- return YTArray(ret, input_units='')
+ return type(self)(ret, input_units='')
- return YTArray(super(YTArray, self).__pow__(power))
+ return super(YTArray, self).__pow__(power)
def __abs__(self):
""" Return a YTArray with the abs of the data. """
- return YTArray(super(YTArray, self).__abs__())
+ return super(YTArray, self).__abs__()
def sqrt(self):
"""
@@ -1061,18 +1060,17 @@
take the 1/2 power of the units.
"""
- return YTArray(super(YTArray, self).sqrt(),
- input_units=self.units**0.5)
+ return type(self)(super(YTArray, self).sqrt(),
+ input_units=self.units**0.5)
#
# Start comparison operators.
#
- # @todo: outsource to a single method with an op argument.
-
def __lt__(self, other):
""" Test if this is less than the object on the right. """
- oth = validate_comparison_units(self, other, 'less_than') # converts if possible
+ # converts if possible
+ oth = validate_comparison_units(self, other, 'less_than')
return super(YTArray, self).__lt__(oth)
def __le__(self, other):
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160330/8002e094/attachment-0002.htm>
More information about the yt-svn
mailing list