def test_one_day_one_file(tmpdir): t0 = utcdate(year=2018, month=1, day=1, hour=10) t1 = utcdate(year=2018, month=1, day=1, hour=13) rng = pd.date_range(t0, t1, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t0, t1) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts, tmpdir, t0, t1)
def test_one_day_one_file(tmpdir): t0 = datetime(2018, 1, 1, 10, tzinfo=utc) t1 = datetime(2018, 1, 1, 13, tzinfo=utc) rng = pd.date_range(t0, t1, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t0, t1) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts, tmpdir, t0, t1)
def test_multiple_writes_to_same_file_with_full_overlap_overwrite(tmpdir): t0 = datetime(2018, 1, 1, 5, tzinfo=utc) t1 = datetime(2018, 1, 1, 15, tzinfo=utc) rng = pd.date_range(t0, t1, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) data2 = data + 1 ts2 = pd.Series(data2, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t0, t1) bazeout(ts2, "test", t0, t1, overwrite=True) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts2, tmpdir, t0, t1) assert_correct_raw_values(ts2, tmpdir, t0)
def test_multiple_writes_to_same_file_with_left_overlap_overwrite(tmpdir): t0 = datetime(2018, 1, 1, 5, tzinfo=utc) t1 = datetime(2018, 1, 1, 8, tzinfo=utc) t2 = datetime(2018, 1, 1, 10, tzinfo=utc) t3 = datetime(2018, 1, 1, 15, tzinfo=utc) rng = pd.date_range(t0, t3, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) data2 = data + 1 ts2 = pd.Series(data2, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t1, t3) bazeout(ts2, "test", t0, t2, overwrite=True) expected = pd.concat([ts2[:(t2 - eps)], ts[t2:]], sort=True) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(expected, tmpdir, t0, t3) assert_correct_raw_values(expected, tmpdir, t0)
def test_multiple_writes_to_same_file_with_right_overlap_overwrite(tmpdir): t0 = utcdate(year=2018, month=1, day=1, hour=5) t1 = utcdate(year=2018, month=1, day=1, hour=8) t2 = utcdate(year=2018, month=1, day=1, hour=10) t3 = utcdate(year=2018, month=1, day=1, hour=15) rng = pd.date_range(t0, t3, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) data2 = data + 1 ts2 = pd.Series(data2, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t0, t2) bazeout(ts2, "test", t1, t3, overwrite=True) expected = pd.concat([ts[:(t1 - eps)], ts2[t1:]], sort=True) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(expected, tmpdir, t0, t3) assert_correct_raw_values(expected, tmpdir, t0)
def test_multiple_writes_to_same_file_with_overlap_no_overwrite(tmpdir): t0 = datetime(2018, 1, 1, 5, tzinfo=utc) t1 = datetime(2018, 1, 1, 8, tzinfo=utc) t2 = datetime(2018, 1, 1, 10, tzinfo=utc) t3 = datetime(2018, 1, 1, 15, tzinfo=utc) rng = pd.date_range(t0, t3, freq='H', name="time", closed='left') data = np.random.randn(len(rng)) ts = pd.Series(data, name="value", index=rng) bazeout = Bazeoutput(str(tmpdir)) bazeout(ts, "test", t1, t2) with pytest.raises(ValueError): bazeout(ts, "test", t0, (t2 - eps)) with pytest.raises(ValueError): bazeout(ts, "test", (t1 + eps), t3) with pytest.raises(ValueError): bazeout(ts, "test", (t1 + eps), (t2 - eps)) with pytest.raises(ValueError): bazeout(ts, "test", t0, t3) assert_files_list(tmpdir, t0, 1) assert_correctly_loaded(ts[t1:(t2 - eps)], tmpdir, t1, t2)
def generate_output(basedir, ts, start_date=None, end_date=None, tag="test"): bazeout = Bazeoutput(str(basedir)) bazeout(ts, tag, start_date, end_date)