Skip to content

Commit

Permalink
separating external tests
Browse files Browse the repository at this point in the history
stringertheory committed Feb 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 949801a commit bdec3ca
Showing 2 changed files with 110 additions and 110 deletions.
110 changes: 1 addition & 109 deletions tests/test_traces.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import csv
import os
import pickle
from datetime import datetime, timedelta
from datetime import datetime

import pandas as pd
import pytest
from pandas.testing import assert_series_equal

from traces import TimeSeries

@@ -169,112 +167,6 @@ def test_remove_points_from_interval():
assert ts[5] == 0


def test_sample_interval_days():
ts = TimeSeries([(datetime(2012, 1, 1), 400), (datetime(2012, 3, 1), 400)])
ts[datetime(2012, 1, 4) : datetime(2012, 1, 20)] = 10
ts[datetime(2012, 1, 25) : datetime(2012, 2, 7)] = 50
ts[datetime(2012, 1, 19) : datetime(2012, 1, 27)] = 0

sr = ts.sample_interval(
sampling_period=timedelta(days=1), end=datetime(2012, 2, 1)
)
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 10.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 10.0),
(pd.Timestamp("2012-01-07 00:00:00"), 10.0),
(pd.Timestamp("2012-01-08 00:00:00"), 10.0),
(pd.Timestamp("2012-01-09 00:00:00"), 10.0),
(pd.Timestamp("2012-01-10 00:00:00"), 10.0),
(pd.Timestamp("2012-01-11 00:00:00"), 10.0),
(pd.Timestamp("2012-01-12 00:00:00"), 10.0),
(pd.Timestamp("2012-01-13 00:00:00"), 10.0),
(pd.Timestamp("2012-01-14 00:00:00"), 10.0),
(pd.Timestamp("2012-01-15 00:00:00"), 10.0),
(pd.Timestamp("2012-01-16 00:00:00"), 10.0),
(pd.Timestamp("2012-01-17 00:00:00"), 10.0),
(pd.Timestamp("2012-01-18 00:00:00"), 10.0),
(pd.Timestamp("2012-01-19 00:00:00"), 0.0),
(pd.Timestamp("2012-01-20 00:00:00"), 0.0),
(pd.Timestamp("2012-01-21 00:00:00"), 0.0),
(pd.Timestamp("2012-01-22 00:00:00"), 0.0),
(pd.Timestamp("2012-01-23 00:00:00"), 0.0),
(pd.Timestamp("2012-01-24 00:00:00"), 0.0),
(pd.Timestamp("2012-01-25 00:00:00"), 0.0),
(pd.Timestamp("2012-01-26 00:00:00"), 0.0),
(pd.Timestamp("2012-01-27 00:00:00"), 50.0),
(pd.Timestamp("2012-01-28 00:00:00"), 50.0),
(pd.Timestamp("2012-01-29 00:00:00"), 50.0),
(pd.Timestamp("2012-01-30 00:00:00"), 50.0),
(pd.Timestamp("2012-01-31 00:00:00"), 50.0),
]


def test_sample_interval_hours():
ts = TimeSeries([(datetime(2012, 1, 1), 400), (datetime(2012, 1, 10), 400)])

ts[datetime(2012, 1, 4, 12) : datetime(2012, 1, 6, 20)] = 10
ts[datetime(2012, 1, 7, 9) : datetime(2012, 1, 10)] = 50

sr = ts.sample_interval(sampling_period=timedelta(days=1))
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 205.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 75.0),
(pd.Timestamp("2012-01-07 00:00:00"), 181.25),
(pd.Timestamp("2012-01-08 00:00:00"), 50.0),
(pd.Timestamp("2012-01-09 00:00:00"), 50.0),
]

sr = ts.sample_interval(sampling_period=timedelta(days=1), operation="max")
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 400.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 400.0),
(pd.Timestamp("2012-01-07 00:00:00"), 400.0),
(pd.Timestamp("2012-01-08 00:00:00"), 50.0),
(pd.Timestamp("2012-01-09 00:00:00"), 50.0),
]

sr = ts.sample_interval(sampling_period=timedelta(days=1), operation="min")
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 10.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 10.0),
(pd.Timestamp("2012-01-07 00:00:00"), 50.0),
(pd.Timestamp("2012-01-08 00:00:00"), 50.0),
(pd.Timestamp("2012-01-09 00:00:00"), 50.0),
]


def test_sample_interval_index():
start = datetime(2012, 1, 1)
end = datetime(2012, 1, 10)

ts = TimeSeries([(start, 400), (end, 400)])

ts[datetime(2012, 1, 4, 12) : datetime(2012, 1, 6, 20)] = 10
ts[datetime(2012, 1, 7, 9) : datetime(2012, 1, 10)] = 50

idx = pd.date_range(start, end, freq="D")
sr = ts.sample_interval(sampling_period=timedelta(days=1))
sr2 = ts.sample_interval(idx=idx)

assert_series_equal(sr, sr2)


def test_pickle():
ts = TimeSeries(default=False)
ts[1] = True
110 changes: 109 additions & 1 deletion tests/test_traces_external.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import csv
import os
from datetime import datetime
from datetime import datetime, timedelta

import pandas as pd
from dateutil.parser import parse as date_parse
from pandas.testing import assert_series_equal

from traces import TimeSeries

@@ -25,3 +27,109 @@ def test_csv():
assert ts[datetime(2000, 1, 1, 9)] is None
assert ts[datetime(2000, 1, 1, 10, 30)] == "15"
assert ts[datetime(2000, 1, 1, 20)] == "nan"


def test_sample_interval_days():
ts = TimeSeries([(datetime(2012, 1, 1), 400), (datetime(2012, 3, 1), 400)])
ts[datetime(2012, 1, 4) : datetime(2012, 1, 20)] = 10
ts[datetime(2012, 1, 25) : datetime(2012, 2, 7)] = 50
ts[datetime(2012, 1, 19) : datetime(2012, 1, 27)] = 0

sr = ts.sample_interval(
sampling_period=timedelta(days=1), end=datetime(2012, 2, 1)
)
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 10.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 10.0),
(pd.Timestamp("2012-01-07 00:00:00"), 10.0),
(pd.Timestamp("2012-01-08 00:00:00"), 10.0),
(pd.Timestamp("2012-01-09 00:00:00"), 10.0),
(pd.Timestamp("2012-01-10 00:00:00"), 10.0),
(pd.Timestamp("2012-01-11 00:00:00"), 10.0),
(pd.Timestamp("2012-01-12 00:00:00"), 10.0),
(pd.Timestamp("2012-01-13 00:00:00"), 10.0),
(pd.Timestamp("2012-01-14 00:00:00"), 10.0),
(pd.Timestamp("2012-01-15 00:00:00"), 10.0),
(pd.Timestamp("2012-01-16 00:00:00"), 10.0),
(pd.Timestamp("2012-01-17 00:00:00"), 10.0),
(pd.Timestamp("2012-01-18 00:00:00"), 10.0),
(pd.Timestamp("2012-01-19 00:00:00"), 0.0),
(pd.Timestamp("2012-01-20 00:00:00"), 0.0),
(pd.Timestamp("2012-01-21 00:00:00"), 0.0),
(pd.Timestamp("2012-01-22 00:00:00"), 0.0),
(pd.Timestamp("2012-01-23 00:00:00"), 0.0),
(pd.Timestamp("2012-01-24 00:00:00"), 0.0),
(pd.Timestamp("2012-01-25 00:00:00"), 0.0),
(pd.Timestamp("2012-01-26 00:00:00"), 0.0),
(pd.Timestamp("2012-01-27 00:00:00"), 50.0),
(pd.Timestamp("2012-01-28 00:00:00"), 50.0),
(pd.Timestamp("2012-01-29 00:00:00"), 50.0),
(pd.Timestamp("2012-01-30 00:00:00"), 50.0),
(pd.Timestamp("2012-01-31 00:00:00"), 50.0),
]


def test_sample_interval_hours():
ts = TimeSeries([(datetime(2012, 1, 1), 400), (datetime(2012, 1, 10), 400)])

ts[datetime(2012, 1, 4, 12) : datetime(2012, 1, 6, 20)] = 10
ts[datetime(2012, 1, 7, 9) : datetime(2012, 1, 10)] = 50

sr = ts.sample_interval(sampling_period=timedelta(days=1))
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 205.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 75.0),
(pd.Timestamp("2012-01-07 00:00:00"), 181.25),
(pd.Timestamp("2012-01-08 00:00:00"), 50.0),
(pd.Timestamp("2012-01-09 00:00:00"), 50.0),
]

sr = ts.sample_interval(sampling_period=timedelta(days=1), operation="max")
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 400.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 400.0),
(pd.Timestamp("2012-01-07 00:00:00"), 400.0),
(pd.Timestamp("2012-01-08 00:00:00"), 50.0),
(pd.Timestamp("2012-01-09 00:00:00"), 50.0),
]

sr = ts.sample_interval(sampling_period=timedelta(days=1), operation="min")
assert list(sr.items()) == [
(pd.Timestamp("2012-01-01 00:00:00"), 400.0),
(pd.Timestamp("2012-01-02 00:00:00"), 400.0),
(pd.Timestamp("2012-01-03 00:00:00"), 400.0),
(pd.Timestamp("2012-01-04 00:00:00"), 10.0),
(pd.Timestamp("2012-01-05 00:00:00"), 10.0),
(pd.Timestamp("2012-01-06 00:00:00"), 10.0),
(pd.Timestamp("2012-01-07 00:00:00"), 50.0),
(pd.Timestamp("2012-01-08 00:00:00"), 50.0),
(pd.Timestamp("2012-01-09 00:00:00"), 50.0),
]


def test_sample_interval_index():
start = datetime(2012, 1, 1)
end = datetime(2012, 1, 10)

ts = TimeSeries([(start, 400), (end, 400)])

ts[datetime(2012, 1, 4, 12) : datetime(2012, 1, 6, 20)] = 10
ts[datetime(2012, 1, 7, 9) : datetime(2012, 1, 10)] = 50

idx = pd.date_range(start, end, freq="D")
sr = ts.sample_interval(sampling_period=timedelta(days=1))
sr2 = ts.sample_interval(idx=idx)

assert_series_equal(sr, sr2)

0 comments on commit bdec3ca

Please sign in to comment.