10
10
11
11
class TestDataFramePctChange :
12
12
@pytest .mark .parametrize (
13
- "periods,fill_method,limit,exp" ,
13
+ "periods, fill_method, limit, exp" ,
14
14
[
15
15
(1 , "ffill" , None , [np .nan , np .nan , np .nan , 1 , 1 , 1.5 , 0 , 0 ]),
16
16
(1 , "ffill" , 1 , [np .nan , np .nan , np .nan , 1 , 1 , 1.5 , 0 , np .nan ]),
@@ -28,7 +28,12 @@ def test_pct_change_with_nas(
28
28
vals = [np .nan , np .nan , 1 , 2 , 4 , 10 , np .nan , np .nan ]
29
29
obj = frame_or_series (vals )
30
30
31
- res = obj .pct_change (periods = periods , fill_method = fill_method , limit = limit )
31
+ msg = (
32
+ "The 'fill_method' and 'limit' keywords in "
33
+ f"{ type (obj ).__name__ } .pct_change are deprecated"
34
+ )
35
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
36
+ res = obj .pct_change (periods = periods , fill_method = fill_method , limit = limit )
32
37
tm .assert_equal (res , frame_or_series (exp ))
33
38
34
39
def test_pct_change_numeric (self ):
@@ -40,21 +45,34 @@ def test_pct_change_numeric(self):
40
45
pnl .iat [1 , 1 ] = np .nan
41
46
pnl .iat [2 , 3 ] = 60
42
47
48
+ msg = (
49
+ "The 'fill_method' and 'limit' keywords in "
50
+ "DataFrame.pct_change are deprecated"
51
+ )
52
+
43
53
for axis in range (2 ):
44
54
expected = pnl .ffill (axis = axis ) / pnl .ffill (axis = axis ).shift (axis = axis ) - 1
45
- result = pnl .pct_change (axis = axis , fill_method = "pad" )
46
55
56
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
57
+ result = pnl .pct_change (axis = axis , fill_method = "pad" )
47
58
tm .assert_frame_equal (result , expected )
48
59
49
60
def test_pct_change (self , datetime_frame ):
50
- rs = datetime_frame .pct_change (fill_method = None )
61
+ msg = (
62
+ "The 'fill_method' and 'limit' keywords in "
63
+ "DataFrame.pct_change are deprecated"
64
+ )
65
+
66
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
67
+ rs = datetime_frame .pct_change (fill_method = None )
51
68
tm .assert_frame_equal (rs , datetime_frame / datetime_frame .shift (1 ) - 1 )
52
69
53
70
rs = datetime_frame .pct_change (2 )
54
71
filled = datetime_frame .fillna (method = "pad" )
55
72
tm .assert_frame_equal (rs , filled / filled .shift (2 ) - 1 )
56
73
57
- rs = datetime_frame .pct_change (fill_method = "bfill" , limit = 1 )
74
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
75
+ rs = datetime_frame .pct_change (fill_method = "bfill" , limit = 1 )
58
76
filled = datetime_frame .fillna (method = "bfill" , limit = 1 )
59
77
tm .assert_frame_equal (rs , filled / filled .shift (1 ) - 1 )
60
78
@@ -88,18 +106,31 @@ def test_pct_change_shift_over_nas(self):
88
106
def test_pct_change_periods_freq (
89
107
self , datetime_frame , freq , periods , fill_method , limit
90
108
):
91
- # GH#7292
92
- rs_freq = datetime_frame .pct_change (
93
- freq = freq , fill_method = fill_method , limit = limit
94
- )
95
- rs_periods = datetime_frame .pct_change (
96
- periods , fill_method = fill_method , limit = limit
109
+ msg = (
110
+ "The 'fill_method' and 'limit' keywords in "
111
+ "DataFrame.pct_change are deprecated"
97
112
)
113
+
114
+ # GH#7292
115
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
116
+ rs_freq = datetime_frame .pct_change (
117
+ freq = freq , fill_method = fill_method , limit = limit
118
+ )
119
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
120
+ rs_periods = datetime_frame .pct_change (
121
+ periods , fill_method = fill_method , limit = limit
122
+ )
98
123
tm .assert_frame_equal (rs_freq , rs_periods )
99
124
100
125
empty_ts = DataFrame (index = datetime_frame .index , columns = datetime_frame .columns )
101
- rs_freq = empty_ts .pct_change (freq = freq , fill_method = fill_method , limit = limit )
102
- rs_periods = empty_ts .pct_change (periods , fill_method = fill_method , limit = limit )
126
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
127
+ rs_freq = empty_ts .pct_change (
128
+ freq = freq , fill_method = fill_method , limit = limit
129
+ )
130
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
131
+ rs_periods = empty_ts .pct_change (
132
+ periods , fill_method = fill_method , limit = limit
133
+ )
103
134
tm .assert_frame_equal (rs_freq , rs_periods )
104
135
105
136
@@ -109,7 +140,14 @@ def test_pct_change_with_duplicated_indices(fill_method):
109
140
data = DataFrame (
110
141
{0 : [np .nan , 1 , 2 , 3 , 9 , 18 ], 1 : [0 , 1 , np .nan , 3 , 9 , 18 ]}, index = ["a" , "b" ] * 3
111
142
)
112
- result = data .pct_change (fill_method = fill_method )
143
+
144
+ msg = (
145
+ "The 'fill_method' and 'limit' keywords in "
146
+ "DataFrame.pct_change are deprecated"
147
+ )
148
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
149
+ result = data .pct_change (fill_method = fill_method )
150
+
113
151
if fill_method is None :
114
152
second_column = [np .nan , np .inf , np .nan , np .nan , 2.0 , 1.0 ]
115
153
else :
0 commit comments