-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_frame.py
46 lines (34 loc) · 1.29 KB
/
test_frame.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
import math
from datetime import datetime
import pandas as pd
from phc.easy.frame import Frame
def test_frame_expand_date_out_of_range():
original = pd.DataFrame(
[
{"effectiveDateTime": "2020-09-15 12:31:00-0500", "id": "obs1"},
{"effectiveDateTime": "0217-05-04 12:31:00-0500", "id": "obs2"},
]
)
expanded = Frame.expand(original)
assert expanded.at[0, "effectiveDateTime.tz"] == -5.0
assert expanded.at[0, "effectiveDateTime.local"] == pd.Timestamp(
"2020-09-15 12:31:00", tz="utc"
)
assert math.isnan(expanded.at[1, "effectiveDateTime.tz"])
assert pd.isna(expanded.at[1, "effectiveDateTime.local"])
def test_local_and_timezone_split():
original = pd.DataFrame(
[
{"effectiveDateTime": "2020-08-08 11:00:00+0300", "id": "obs1"},
{"effectiveDateTime": "2020-08-09 10:00:00-0400", "id": "obs2"},
]
)
expanded = Frame.expand(original)
assert expanded.at[0, "effectiveDateTime.tz"] == 3.0
assert expanded.at[0, "effectiveDateTime.local"] == pd.Timestamp(
"2020-08-08 11:00:00", tz="utc"
)
assert expanded.at[1, "effectiveDateTime.tz"] == -4.0
assert expanded.at[1, "effectiveDateTime.local"] == pd.Timestamp(
"2020-08-09 10:00:00", tz="utc"
)