def testArrayEquals(self): if IGNORE_TEST: return arr1 = np.array([1, 2, 3, 4]) arr1 = np.reshape(arr1, (2, 2)) self.assertTrue(namedTimeseries.arrayEquals(arr1, arr1)) arr2 = 1.0001 * arr1 self.assertFalse(namedTimeseries.arrayEquals(arr1, arr2))
def testConcatenateColumns(self): if IGNORE_TEST: return ts = self.timeseries.concatenateColumns(self.timeseries) newNames = ["%s_" % c for c in self.timeseries.colnames] self.assertTrue( namedTimeseries.arrayEquals( ts[newNames], self.timeseries[self.timeseries.colnames])) self.assertEqual(len(ts), len(self.timeseries)) self.assertTrue( namedTimeseries.arrayEquals(ts[TIME], self.timeseries[TIME])) # ts = self.timeseries.concatenateColumns( [self.timeseries, self.timeseries]) self.assertEqual(3 * len(self.timeseries.colnames), len(ts.colnames))
def testConstructorNamedArray(self): if IGNORE_TEST: return namedArray = self.model.simulate(0, 100, 30) ts = NamedTimeseries(namedArray=namedArray) self.assertTrue( namedTimeseries.arrayEquals(namedArray.flatten(), ts.values.flatten()))
def testSetitem(self): if IGNORE_TEST: return self.timeseries["S1"] = self.timeseries["S2"] self.assertTrue( namedTimeseries.arrayEquals(self.timeseries["S1"], self.timeseries["S2"])) value = -20 self.timeseries["S19"] = value self.assertEqual(self.timeseries["S19"].sum(), len(self.timeseries) * value)
def testGetitem(self): if IGNORE_TEST: return times = self.timeseries[TIME] # Access time column with different case refs = ["TiMe", "S1"] self.assertTrue( namedTimeseries.arrayEquals(self.timeseries[refs], self.timeseries[refs])) self.assertTrue( namedTimeseries.arrayEquals(self.timeseries[TIME], self.timeseries["TimE"])) self.assertTrue( namedTimeseries.arrayEquals(self.timeseries[TIME], self.timeseries["TimE"])) self.assertEqual(len(times), len(self.timeseries)) self.assertEqual(min(times), self.timeseries.start) self.assertEqual(max(times), self.timeseries.end) # Get multiple values at once values = self.timeseries[self.timeseries.colnames] trues = np.array([ v1 == v2 for v1, v2 in zip(values, self.timeseries.values[:, 1:]) ]) self.assertTrue(all(trues.flatten()))