16
16
17
17
18
18
class TestDatetimeLikeStatReductions :
19
- @pytest .mark .parametrize ("box" , [Series , pd .Index , pd .array ])
20
- def test_dt64_mean (self , tz_naive_fixture , box ):
19
+ def test_dt64_mean (self , tz_naive_fixture , index_or_series_or_array ):
21
20
tz = tz_naive_fixture
22
21
23
22
dti = date_range ("2001-01-01" , periods = 11 , tz = tz )
24
23
# shuffle so that we are not just working with monotone-increasing
25
24
dti = dti .take ([4 , 1 , 3 , 10 , 9 , 7 , 8 , 5 , 0 , 2 , 6 ])
26
25
dtarr = dti ._data
27
26
28
- obj = box (dtarr )
27
+ obj = index_or_series_or_array (dtarr )
29
28
assert obj .mean () == pd .Timestamp ("2001-01-06" , tz = tz )
30
29
assert obj .mean (skipna = False ) == pd .Timestamp ("2001-01-06" , tz = tz )
31
30
32
31
# dtarr[-2] will be the first date 2001-01-1
33
32
dtarr [- 2 ] = pd .NaT
34
33
35
- obj = box (dtarr )
34
+ obj = index_or_series_or_array (dtarr )
36
35
assert obj .mean () == pd .Timestamp ("2001-01-06 07:12:00" , tz = tz )
37
36
assert obj .mean (skipna = False ) is pd .NaT
38
37
39
- @pytest .mark .parametrize ("box" , [Series , pd .Index , pd .array ])
40
38
@pytest .mark .parametrize ("freq" , ["s" , "h" , "D" , "W" , "B" ])
41
- def test_period_mean (self , box , freq ):
39
+ def test_period_mean (self , index_or_series_or_array , freq ):
42
40
# GH#24757
43
41
dti = date_range ("2001-01-01" , periods = 11 )
44
42
# shuffle so that we are not just working with monotone-increasing
@@ -48,7 +46,7 @@ def test_period_mean(self, box, freq):
48
46
msg = r"PeriodDtype\[B\] is deprecated"
49
47
with tm .assert_produces_warning (warn , match = msg ):
50
48
parr = dti ._data .to_period (freq )
51
- obj = box (parr )
49
+ obj = index_or_series_or_array (parr )
52
50
with pytest .raises (TypeError , match = "ambiguous" ):
53
51
obj .mean ()
54
52
with pytest .raises (TypeError , match = "ambiguous" ):
@@ -62,13 +60,12 @@ def test_period_mean(self, box, freq):
62
60
with pytest .raises (TypeError , match = "ambiguous" ):
63
61
obj .mean (skipna = True )
64
62
65
- @pytest .mark .parametrize ("box" , [Series , pd .Index , pd .array ])
66
- def test_td64_mean (self , box ):
63
+ def test_td64_mean (self , index_or_series_or_array ):
67
64
m8values = np .array ([0 , 3 , - 2 , - 7 , 1 , 2 , - 1 , 3 , 5 , - 2 , 4 ], "m8[D]" )
68
65
tdi = pd .TimedeltaIndex (m8values ).as_unit ("ns" )
69
66
70
67
tdarr = tdi ._data
71
- obj = box (tdarr , copy = False )
68
+ obj = index_or_series_or_array (tdarr , copy = False )
72
69
73
70
result = obj .mean ()
74
71
expected = np .array (tdarr ).mean ()
0 commit comments