2
2
import unittest
3
3
4
4
import numpy as np
5
+ from numpy .testing .decorators import slow
5
6
6
7
from pandas import Series , date_range
7
8
import pandas .util .testing as tm
@@ -36,6 +37,34 @@ def test_daily(self):
36
37
leaps .index = leaps .index .year
37
38
tm .assert_series_equal (annual [day ].dropna (), leaps )
38
39
40
+ @slow
41
+ def test_hourly (self ):
42
+ rng_hourly = date_range ('1/1/1994' , periods = (18 * 8760 + 4 * 24 ), freq = 'H' )
43
+ data_hourly = np .random .randint (100 , 350 , rng_hourly .size )
44
+ data_hourly = data_hourly .astype ('float64' )
45
+ ts_hourly = Series (data_hourly , index = rng_hourly )
46
+
47
+ grouped = ts_hourly .groupby (ts_hourly .index .year )
48
+ hoy = grouped .apply (lambda x : x .reset_index (drop = True ))
49
+ hoy = hoy .index .droplevel (0 ).values
50
+ hoy [- isleapyear (ts_hourly .index .year ) & (hoy >= 1416 )] += 24
51
+ hoy += 1
52
+
53
+ annual = pivot_annual (ts_hourly )
54
+
55
+ for i in [1 , 1416 , 1417 , 1418 , 8784 ]:
56
+ subset = ts_hourly [hoy == i ]
57
+ subset .index = [x .year for x in subset .index ]
58
+
59
+ tm .assert_series_equal (annual [i ].dropna (), subset )
60
+
61
+ leaps = ts_hourly [(ts_hourly .index .month == 2 ) &
62
+ (ts_hourly .index .day == 29 ) &
63
+ (ts_hourly .index .hour == 0 )]
64
+ hour = leaps .index .dayofyear [0 ] * 24 - 23
65
+ leaps .index = leaps .index .year
66
+ tm .assert_series_equal (annual [hour ].dropna (), leaps )
67
+
39
68
def test_weekly (self ):
40
69
pass
41
70
@@ -46,7 +75,6 @@ def test_monthly(self):
46
75
annual = pivot_annual (ts , 'M' )
47
76
48
77
month = ts .index .month
49
-
50
78
for i in range (1 , 13 ):
51
79
subset = ts [month == i ]
52
80
subset .index = [x .year for x in subset .index ]
0 commit comments