Implements tests and code for real, imag and T properties

Close #171
This commit is contained in:
Hernan Grecco
2014-07-10 21:17:58 -03:00
parent 75694b07b0
commit 2401b7b9fa
2 changed files with 25 additions and 0 deletions

View File

@@ -695,6 +695,18 @@ class _Quantity(object):
raise DimensionalityError('dimensionless', self.units)
self.magnitude.put(indices, values, mode)
@property
def real(self):
return self.__class__(self._magnitude.real, self.units)
@property
def imag(self):
return self.__class__(self._magnitude.imag, self.units)
@property
def T(self):
return self.__class__(self._magnitude.T, self.units)
def searchsorted(self, v, side='left'):
if isinstance(v, self.__class__):
v = v.to(self).magnitude

View File

@@ -453,3 +453,16 @@ class TestIssuesNP(QuantityTestCase):
q[1] = float('NaN')
self.assertNotEqual(q[1], 2.)
self.assertTrue(math.isnan(q[1].magnitude))
def test_issue171_real_imag(self):
qr = [1., 2., 3., 4.] * self.ureg.meter
qi = [4., 3., 2., 1.] * self.ureg.meter
q = qr + 1j * qi
self.assertQuantityEqual(q.real, qr)
self.assertQuantityEqual(q.imag, qi)
def test_issue171_T(self):
a = np.asarray([[1., 2., 3., 4.],[4., 3., 2., 1.]])
q1 = a * self.ureg.meter
q2 = a.T * self.ureg.meter
self.assertQuantityEqual(q1.T, q2)