Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit e10f984

Browse files
authored
Add 2D array test test_datetime_features.py
1 parent dfefee0 commit e10f984

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
import numpy as np
2-
from datetime import datetime
3-
4-
from ocf_datapipes.transform.numpy_batch import AddTrigonometricDateTime
52

63
from ocf_datapipes.transform.numpy_batch.datetime_features import _get_date_time_in_pi
74

85

96
def test_get_date_time_in_pi():
10-
times = [
11-
"2020-01-01T00:00:01",
12-
"2020-04-01T06:00:00",
13-
"2020-07-01T12:00:00",
14-
"2020-09-30T18:00:00",
15-
"2020-12-31T23:59:59",
16-
"2021-01-01T00:00:01",
17-
"2021-04-02T06:00:00",
18-
"2021-07-02T12:00:00",
19-
"2021-10-01T18:00:00",
20-
"2021-12-31T23:59:59",
21-
]
22-
23-
expected_times_in_pi = [0, 0.5 * np.pi, np.pi, 1.5 * np.pi, 2 * np.pi] * 2
24-
25-
times = np.array([datetime.fromisoformat(time) for time in times], dtype="datetime64[s]")
7+
times = np.array([
8+
"2020-01-01T00:00:00", "2020-04-01T06:00:00",
9+
"2020-07-01T12:00:00", "2020-09-30T18:00:00",
10+
"2020-12-31T23:59:59",
11+
"2021-01-01T00:00:00", "2021-04-02T06:00:00",
12+
"2021-07-02T12:00:00", "2021-10-01T18:00:00",
13+
"2021-12-31T23:59:59"
14+
]).reshape((2, 5))
15+
16+
expected_times_in_pi = np.array([0, 0.5*np.pi, np.pi, 1.5*np.pi, 2*np.pi] * 2).reshape((2,5))
17+
18+
times = times.astype("datetime64[s]")
2619

2720
date_in_pi, time_in_pi = _get_date_time_in_pi(times)
2821

@@ -34,3 +27,9 @@ def test_get_date_time_in_pi():
3427
assert np.isclose(np.sin(time_in_pi), np.sin(expected_times_in_pi), atol=7.3e-05).all()
3528
assert np.isclose(np.cos(date_in_pi), np.cos(expected_times_in_pi), atol=0.02182).all()
3629
assert np.isclose(np.sin(date_in_pi), np.sin(expected_times_in_pi), atol=0.02182).all()
30+
31+
# 1D array test
32+
assert np.isclose(np.cos(time_in_pi[0]), np.cos(expected_times_in_pi[0]), atol=7.3e-05).all()
33+
assert np.isclose(np.sin(time_in_pi[0]), np.sin(expected_times_in_pi[0]), atol=7.3e-05).all()
34+
assert np.isclose(np.cos(date_in_pi[0]), np.cos(expected_times_in_pi[0]), atol=0.02182).all()
35+
assert np.isclose(np.sin(date_in_pi[0]), np.sin(expected_times_in_pi[0]), atol=0.02182).all()

0 commit comments

Comments
 (0)