-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_utils.py
94 lines (72 loc) · 3 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import numpy as np
import pandas as pd
from enlopy.utils import make_timeseries , clean_convert, _freq_to_sec
class Test_make_timeseries():
def test_ndarray_h(self):
a = np.random.rand(8760)
b = make_timeseries(a)
assert isinstance(b, pd.Series)
assert np.isclose(sum(a), sum(b))
def test_ndarray_15m(self):
a = np.random.rand(35040)
b = make_timeseries(a)
assert isinstance(b, pd.Series)
assert np.isclose(sum(a), sum(b))
def test_ndarray_x(self):
a = np.random.rand(8730)
b = make_timeseries(a, freq='h')
assert isinstance(b, pd.Series)
assert np.isclose(sum(a), sum(b))
def test_pdseries(self):
a = pd.Series(np.random.rand(8760))
b = make_timeseries(a)
assert isinstance(b, pd.Series)
assert np.isclose(sum(a), sum(b))
def test_pddataframe(self):
a = pd.DataFrame(np.random.rand(8760))
b = make_timeseries(a)
assert isinstance(b, pd.DataFrame)
def test_pddataframe_2d(self):
a = pd.DataFrame(np.random.rand(35040,3))
b = make_timeseries(a)
assert isinstance(b, pd.DataFrame)
def test_2d_ndarray(self):
a = np.random.rand(8760,5)
b = make_timeseries(a)
assert isinstance(b, pd.DataFrame)
def test_empty_frame(self):
a = np.array([])
b = make_timeseries(a, freq='h')
assert isinstance(b, pd.Series) and len(b)==0
def test_empty_frame_to_indexed_empty(self):
b = make_timeseries(freq='h', length=8760)
assert isinstance(b, pd.Series) and len(b) == 8760
def test_multiannual_timeseries(self):
a = np.random.rand(8760*2)
b = make_timeseries(a, freq='h')
assert isinstance(b, pd.Series)
assert np.isclose(sum(a), sum(b))
class Test_clean_convert():
def test_ndarray_to_series_indexed(self):
a = np.random.rand(8760)
b = clean_convert(a, force_timed_index=True, always_df=False)
assert isinstance(b, pd.Series) and isinstance(b.index, pd.DatetimeIndex)
def test_ndarray_to_df_indexed(self):
a = np.random.rand(8760)
b = clean_convert(a, force_timed_index=True, always_df=True)
assert isinstance(b, pd.DataFrame) and isinstance(b.index, pd.DatetimeIndex)
def test_1d_series_to_frame(self):
a = pd.Series(np.random.rand(8760))
b = clean_convert(a, force_timed_index=True, always_df=True)
assert isinstance(b, pd.DataFrame) and isinstance(b.index, pd.DatetimeIndex)
def test_2d_ndarray_to_df_indexed(self):
a = np.random.rand(8760, 2)
b = clean_convert(a, force_timed_index=True, always_df=True)
assert isinstance(b, pd.DataFrame) and isinstance(b.index, pd.DatetimeIndex)
def test_list_to_series(self):
a = list(np.random.rand(8760))
b = clean_convert(a, force_timed_index=True, always_df=False)
assert isinstance(b, pd.Series)
def test_freq_to_sec():
a = _freq_to_sec('d')
assert a == 60 * 60 * 24