Commit 5b4abbb5 authored by Jason Swails's avatar Jason Swails
Browse files

Oops... Forgot unit on the reshape command.

Add a test for the various numpy attributes (and the arguments they take) for
the unit module.
parent a5c00fa5
...@@ -580,7 +580,7 @@ class Quantity(object): ...@@ -580,7 +580,7 @@ class Quantity(object):
same units as the current object rather than a plain numpy.ndarray same units as the current object rather than a plain numpy.ndarray
""" """
try: try:
return Quantity(self._value.reshape(shape, order=order)) return Quantity(self._value.reshape(shape, order=order), self.unit)
except AttributeError: except AttributeError:
raise AttributeError('Only numpy array Quantity objects can be ' raise AttributeError('Only numpy array Quantity objects can be '
'reshaped') 'reshaped')
......
...@@ -75,7 +75,7 @@ class TestNumpyCompatibility(unittest.TestCase): ...@@ -75,7 +75,7 @@ class TestNumpyCompatibility(unittest.TestCase):
f.addMap(10, energy) f.addMap(10, energy)
size, energy_out = f.getMapParameters(0) size, energy_out = f.getMapParameters(0)
assert size == 10 self.assertEqual(size, 10)
np.testing.assert_array_almost_equal(energy, np.asarray(energy_out)) np.testing.assert_array_almost_equal(energy, np.asarray(energy_out))
class TestNumpyUnits(unittest.TestCase): class TestNumpyUnits(unittest.TestCase):
...@@ -85,7 +85,7 @@ class TestNumpyUnits(unittest.TestCase): ...@@ -85,7 +85,7 @@ class TestNumpyUnits(unittest.TestCase):
def testNumpyAttributes(self): def testNumpyAttributes(self):
d = self.data.reshape((100, 3)) d = self.data.reshape((100, 3))
self.assertTrue(unit.is_quantity(d)) self.assertTrue(unit.is_quantity(d) and d.unit is unit.nanometers)
self.assertTrue(unit.is_quantity(d.sum())) self.assertTrue(unit.is_quantity(d.sum()))
self.assertTrue(unit.is_quantity(d.sum(axis=0))) self.assertTrue(unit.is_quantity(d.sum(axis=0)))
self.assertTrue(unit.is_quantity(d.std())) self.assertTrue(unit.is_quantity(d.std()))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment