def test_with_stride_and_lag(self): reader = CSVReader(self.filename1) for s in [2, 3, 7, 10]: for t in [1, 23, 7, 59]: chunks = [] chunks_lag = [] it = reader.iterator(stride=s, lag=t) with it: for _, X, Y in it: chunks.append(X) chunks_lag.append(Y) chunks = np.vstack(chunks) chunks_lag = np.vstack(chunks_lag) actual_lagged = self.data[t::s] np.testing.assert_almost_equal( chunks, self.data[::s][0:len(actual_lagged)], err_msg="output is not equal for" " lag %i and stride %i" % (t, s)) np.testing.assert_almost_equal( chunks_lag, self.data[t::s], err_msg="output is not equal for" " lag %i and stride %i" % (t, s))
def test_reset(self): reader = CSVReader((self.filename1, self.filename2)) it = reader.iterator() data = [chunk for chunk in it] it.reset() data2 = [chunk for chunk in it] np.testing.assert_equal(data, data2)
def test_with_lag(self): reader = CSVReader(self.filename1) for t in [23, 7, 59]: chunks = [] for _, _, Y in reader.iterator(stride=1, lag=t): chunks.append(Y) chunks = np.vstack(chunks) np.testing.assert_almost_equal(chunks, self.data[t:])
def test_with_lag(self): reader = CSVReader(self.filename1) for t in [23, 7, 59]: chunks = [] for _, _, Y in reader.iterator(stride=1, lag=t): chunks.append(Y) chunks = np.vstack(chunks) np.testing.assert_almost_equal(chunks, self.data[t:])
def test_read_lagged_small_chunks(self): lag = 200 reader = CSVReader(self.filename1, chunksize=30) lagged_data = self.data[lag:] lagged_chunks = [] for _, _, Y in reader.iterator(lag=lag): # kick out empty chunks if Y.shape[0] > 0: lagged_chunks.append(Y) lagged_chunks = np.vstack(lagged_chunks) np.testing.assert_almost_equal(lagged_chunks, lagged_data)
def test_read_lagged_small_chunks(self): lag = 200 reader = CSVReader(self.filename1, chunksize=30) lagged_data = self.data[lag:] lagged_chunks = [] for _, _, Y in reader.iterator(lag=lag): # kick out empty chunks if Y.shape[0] > 0: lagged_chunks.append(Y) lagged_chunks = np.vstack(lagged_chunks) np.testing.assert_almost_equal(lagged_chunks, lagged_data)
def test_read_lagged_small_chunks(self): lag = 200 reader = CSVReader(self.filename1, chunksize=30) lagged_data = self.data[lag:] lagged_chunks = [] it = reader.iterator(lag=lag) with it: for _, _, Y in it: assert len(Y) > 0 lagged_chunks.append(Y) lagged_chunks = np.vstack(lagged_chunks) np.testing.assert_almost_equal(lagged_chunks, lagged_data)
def test_with_stride_and_lag_with_header(self): reader = CSVReader(self.file_with_header) for s in [2, 3, 7, 10]: for t in [1, 23, 7, 59]: chunks = [] chunks_lag = [] for _, X, Y in reader.iterator(stride=s, lag=t): chunks.append(X) chunks_lag.append(Y) chunks = np.vstack(chunks) chunks_lag = np.vstack(chunks_lag) np.testing.assert_almost_equal(chunks, self.data[::s]) np.testing.assert_almost_equal(chunks_lag, self.data[t::s], err_msg="output is not equal for" " lag %i and stride %i" % (t, s))
def test_with_stride_and_lag_with_header(self): reader = CSVReader(self.file_with_header) for s in [2, 3, 7, 10]: for t in [1, 23, 7, 59]: chunks = [] chunks_lag = [] for _, X, Y in reader.iterator(stride=s, lag=t): chunks.append(X) chunks_lag.append(Y) chunks = np.vstack(chunks) chunks_lag = np.vstack(chunks_lag) np.testing.assert_almost_equal(chunks, self.data[::s]) np.testing.assert_almost_equal( chunks_lag, self.data[t::s], err_msg="output is not equal for" " lag %i and stride %i" % (t, s))
def test_use_cols(self): reader = CSVReader(self.filename1) cols = (0, 2) with reader.iterator(chunk=0, cols=cols, return_trajindex=False) as it: for x in it: np.testing.assert_equal(x, self.data[:, cols])