def test_compatible_metadata_merge(self):
     a = metaarray.TimeSeries(np.arange(1000), TimeSeries_metadata)
     b = metaarray.TimeSeries(np.arange(1000), TimeSeries_metadata)
     c = a * b
     self.assertTrue(c.metadata.dt == TimeSeries_metadata["dt"])
     self.assertTrue(c.metadata.comments == TimeSeries_metadata["comments"])
     self.assertTrue(c.metadata.segments == TimeSeries_metadata["segments"])
    def test_multiply_correctness(self):
        a = np.random.random(1000)
        b = np.random.random(1000)

        a_TimeSeries = metaarray.TimeSeries(a, TimeSeries_metadata)
        b_TimeSeries = metaarray.TimeSeries(b, TimeSeries_metadata)

        # multiply
        self.assertTrue((a * b == (a_TimeSeries * b_TimeSeries).A).all())
        self.assertTrue((a * b == (a * b_TimeSeries).A).all())
        self.assertTrue((a * b == (a_TimeSeries * b).A).all())

        # in-place multiply
        c = np.array(a, copy=True)
        c *= b_TimeSeries
        self.assertTrue((a * b == c).all())
        d = metaarray.TimeSeries(a_TimeSeries, copy=True)
        d *= b
        self.assertTrue((a * b == d.A).all())
    def test_multiply_type(self):
        """
        See that TimeSeries metadata are retained by a multiplication.
        """
        a = np.random.random(1000)
        b = np.random.random(1000)

        a_TimeSeries = metaarray.TimeSeries(a, TimeSeries_metadata)
        b_TimeSeries = metaarray.TimeSeries(b, TimeSeries_metadata)

        # multiply
        self.assertTrue(
            isinstance(a_TimeSeries * b_TimeSeries, metaarray.TimeSeries))
        self.assertTrue(isinstance(a * b_TimeSeries, metaarray.TimeSeries))
        self.assertTrue(isinstance(a_TimeSeries * b, metaarray.TimeSeries))

        # in-place multiply
        c = np.array(a, copy=True)
        c *= b_TimeSeries
        self.assertTrue(isinstance(c, np.ndarray))
        d = metaarray.TimeSeries(a_TimeSeries, copy=True)
        d *= b
        self.assertTrue(isinstance(d, metaarray.TimeSeries))
 def test_identity(self):
     """
     See that the TimeSeries wrapping doesn't touch array data
     """
     arr = np.arange(100, dtype=np.float32)
     spec = metaarray.TimeSeries(arr, TimeSeries_metadata)
     self.assertTrue((arr == spec.A).all())
     arr = np.arange(100, dtype=np.float64)
     spec = metaarray.TimeSeries(arr, TimeSeries_metadata)
     self.assertTrue((arr == spec.A).all())
     arr = np.ones(100, dtype=np.bool8)
     spec = metaarray.TimeSeries(arr, TimeSeries_metadata)
     self.assertTrue((arr == spec.A).all())
     arr = np.arange(100, dtype=np.int32)
     spec = metaarray.TimeSeries(arr, TimeSeries_metadata)
     self.assertTrue((arr == spec.A).all())
     arr = np.arange(100, dtype=np.int64)
     spec = metaarray.TimeSeries(arr, TimeSeries_metadata)
     self.assertTrue((arr == spec.A).all())
     arr = np.arange(100, dtype=np.int64)
     spec = metaarray.TimeSeries(arr, TimeSeries_metadata)
     self.assertTrue((arr == spec.A).all())
    def test_incompatible_metadata_merge(self):
        a = metaarray.TimeSeries(np.arange(1000), TimeSeries_metadata)
        b = metaarray.TimeSeries(np.arange(1000), TimeSeries_metadata)

        b.metadata.dt = 2 * a.metadata.dt
        self.assertRaises(AssertionError, operator.mul, a, b)