10
10
11
11
class TestDataFramePctChange :
12
12
@pytest .mark .parametrize (
13
- "periods, fill_method, limit, exp" ,
13
+ "periods, exp" ,
14
14
[
15
- (1 , "ffill" , None , [np .nan , np .nan , np .nan , 1 , 1 , 1.5 , 0 , 0 ]),
16
- (1 , "ffill" , 1 , [np .nan , np .nan , np .nan , 1 , 1 , 1.5 , 0 , np .nan ]),
17
- (1 , "bfill" , None , [np .nan , 0 , 0 , 1 , 1 , 1.5 , np .nan , np .nan ]),
18
- (1 , "bfill" , 1 , [np .nan , np .nan , 0 , 1 , 1 , 1.5 , np .nan , np .nan ]),
19
- (- 1 , "ffill" , None , [np .nan , np .nan , - 0.5 , - 0.5 , - 0.6 , 0 , 0 , np .nan ]),
20
- (- 1 , "ffill" , 1 , [np .nan , np .nan , - 0.5 , - 0.5 , - 0.6 , 0 , np .nan , np .nan ]),
21
- (- 1 , "bfill" , None , [0 , 0 , - 0.5 , - 0.5 , - 0.6 , np .nan , np .nan , np .nan ]),
22
- (- 1 , "bfill" , 1 , [np .nan , 0 , - 0.5 , - 0.5 , - 0.6 , np .nan , np .nan , np .nan ]),
15
+ (1 , [np .nan , np .nan , np .nan , 1 , 1 , 1.5 , np .nan , np .nan ]),
16
+ (- 1 , [np .nan , np .nan , - 0.5 , - 0.5 , - 0.6 , np .nan , np .nan , np .nan ]),
23
17
],
24
18
)
25
- def test_pct_change_with_nas (
26
- self , periods , fill_method , limit , exp , frame_or_series
27
- ):
19
+ def test_pct_change_with_nas (self , periods , exp , frame_or_series ):
28
20
vals = [np .nan , np .nan , 1 , 2 , 4 , 10 , np .nan , np .nan ]
29
21
obj = frame_or_series (vals )
30
22
31
- msg = (
32
- "The 'fill_method' keyword being not None and the 'limit' keyword 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 )
23
+ res = obj .pct_change (periods = periods )
37
24
tm .assert_equal (res , frame_or_series (exp ))
38
25
39
26
def test_pct_change_numeric (self ):
@@ -45,124 +32,82 @@ def test_pct_change_numeric(self):
45
32
pnl .iat [1 , 1 ] = np .nan
46
33
pnl .iat [2 , 3 ] = 60
47
34
48
- msg = (
49
- "The 'fill_method' keyword being not None and the 'limit' keyword in "
50
- "DataFrame.pct_change are deprecated"
51
- )
52
-
53
35
for axis in range (2 ):
54
- expected = pnl .ffill (axis = axis ) / pnl .ffill (axis = axis ).shift (axis = axis ) - 1
55
-
56
- with tm .assert_produces_warning (FutureWarning , match = msg ):
57
- result = pnl .pct_change (axis = axis , fill_method = "pad" )
36
+ expected = pnl / pnl .shift (axis = axis ) - 1
37
+ result = pnl .pct_change (axis = axis )
58
38
tm .assert_frame_equal (result , expected )
59
39
60
40
def test_pct_change (self , datetime_frame ):
61
- msg = (
62
- "The 'fill_method' keyword being not None and the 'limit' keyword in "
63
- "DataFrame.pct_change are deprecated"
64
- )
65
-
66
- rs = datetime_frame .pct_change (fill_method = None )
41
+ rs = datetime_frame .pct_change ()
67
42
tm .assert_frame_equal (rs , datetime_frame / datetime_frame .shift (1 ) - 1 )
68
43
69
44
rs = datetime_frame .pct_change (2 )
70
45
filled = datetime_frame .ffill ()
71
46
tm .assert_frame_equal (rs , filled / filled .shift (2 ) - 1 )
72
47
73
- with tm .assert_produces_warning (FutureWarning , match = msg ):
74
- rs = datetime_frame .pct_change (fill_method = "bfill" , limit = 1 )
75
- filled = datetime_frame .bfill (limit = 1 )
76
- tm .assert_frame_equal (rs , filled / filled .shift (1 ) - 1 )
48
+ rs = datetime_frame .pct_change ()
49
+ tm .assert_frame_equal (rs , datetime_frame / datetime_frame .shift (1 ) - 1 )
77
50
78
51
rs = datetime_frame .pct_change (freq = "5D" )
79
- filled = datetime_frame .ffill ()
80
52
tm .assert_frame_equal (
81
- rs , (filled / filled .shift (freq = "5D" ) - 1 ).reindex_like (filled )
53
+ rs ,
54
+ (datetime_frame / datetime_frame .shift (freq = "5D" ) - 1 ).reindex_like (
55
+ datetime_frame
56
+ ),
82
57
)
83
58
84
59
def test_pct_change_shift_over_nas (self ):
85
60
s = Series ([1.0 , 1.5 , np .nan , 2.5 , 3.0 ])
86
61
87
62
df = DataFrame ({"a" : s , "b" : s })
88
63
89
- msg = "The default fill_method='pad' in DataFrame.pct_change is deprecated"
90
- with tm .assert_produces_warning (FutureWarning , match = msg ):
91
- chg = df .pct_change ()
92
-
93
- expected = Series ([np .nan , 0.5 , 0.0 , 2.5 / 1.5 - 1 , 0.2 ])
64
+ chg = df .pct_change ()
65
+ expected = Series ([np .nan , 0.5 , np .nan , np .nan , 0.2 ])
94
66
edf = DataFrame ({"a" : expected , "b" : expected })
95
67
tm .assert_frame_equal (chg , edf )
96
68
97
69
@pytest .mark .parametrize (
98
- "freq, periods, fill_method, limit " ,
70
+ "freq, periods" ,
99
71
[
100
- ("5B" , 5 , None , None ),
101
- ("3B" , 3 , None , None ),
102
- ("3B" , 3 , "bfill" , None ),
103
- ("7B" , 7 , "pad" , 1 ),
104
- ("7B" , 7 , "bfill" , 3 ),
105
- ("14B" , 14 , None , None ),
72
+ ("5B" , 5 ),
73
+ ("3B" , 3 ),
74
+ ("14B" , 14 ),
106
75
],
107
76
)
108
77
def test_pct_change_periods_freq (
109
- self , datetime_frame , freq , periods , fill_method , limit
78
+ self ,
79
+ datetime_frame ,
80
+ freq ,
81
+ periods ,
110
82
):
111
- msg = (
112
- "The 'fill_method' keyword being not None and the 'limit' keyword in "
113
- "DataFrame.pct_change are deprecated"
114
- )
115
-
116
83
# GH#7292
117
- with tm .assert_produces_warning (FutureWarning , match = msg ):
118
- rs_freq = datetime_frame .pct_change (
119
- freq = freq , fill_method = fill_method , limit = limit
120
- )
121
- with tm .assert_produces_warning (FutureWarning , match = msg ):
122
- rs_periods = datetime_frame .pct_change (
123
- periods , fill_method = fill_method , limit = limit
124
- )
84
+ rs_freq = datetime_frame .pct_change (freq = freq )
85
+ rs_periods = datetime_frame .pct_change (periods )
125
86
tm .assert_frame_equal (rs_freq , rs_periods )
126
87
127
88
empty_ts = DataFrame (index = datetime_frame .index , columns = datetime_frame .columns )
128
- with tm .assert_produces_warning (FutureWarning , match = msg ):
129
- rs_freq = empty_ts .pct_change (
130
- freq = freq , fill_method = fill_method , limit = limit
131
- )
132
- with tm .assert_produces_warning (FutureWarning , match = msg ):
133
- rs_periods = empty_ts .pct_change (
134
- periods , fill_method = fill_method , limit = limit
135
- )
89
+ rs_freq = empty_ts .pct_change (freq = freq )
90
+ rs_periods = empty_ts .pct_change (periods )
136
91
tm .assert_frame_equal (rs_freq , rs_periods )
137
92
138
93
139
- @pytest .mark .parametrize ("fill_method" , ["pad" , "ffill" , None ])
140
- def test_pct_change_with_duplicated_indices (fill_method ):
94
+ def test_pct_change_with_duplicated_indices ():
141
95
# GH30463
142
96
data = DataFrame (
143
97
{0 : [np .nan , 1 , 2 , 3 , 9 , 18 ], 1 : [0 , 1 , np .nan , 3 , 9 , 18 ]}, index = ["a" , "b" ] * 3
144
98
)
145
99
146
- warn = None if fill_method is None else FutureWarning
147
- msg = (
148
- "The 'fill_method' keyword being not None and the 'limit' keyword in "
149
- "DataFrame.pct_change are deprecated"
150
- )
151
- with tm .assert_produces_warning (warn , match = msg ):
152
- result = data .pct_change (fill_method = fill_method )
100
+ result = data .pct_change ()
153
101
154
- if fill_method is None :
155
- second_column = [np .nan , np .inf , np .nan , np .nan , 2.0 , 1.0 ]
156
- else :
157
- second_column = [np .nan , np .inf , 0.0 , 2.0 , 2.0 , 1.0 ]
102
+ second_column = [np .nan , np .inf , np .nan , np .nan , 2.0 , 1.0 ]
158
103
expected = DataFrame (
159
104
{0 : [np .nan , np .nan , 1.0 , 0.5 , 2.0 , 1.0 ], 1 : second_column },
160
105
index = ["a" , "b" ] * 3 ,
161
106
)
162
107
tm .assert_frame_equal (result , expected )
163
108
164
109
165
- def test_pct_change_none_beginning_no_warning ():
110
+ def test_pct_change_none_beginning ():
166
111
# GH#54481
167
112
df = DataFrame (
168
113
[
0 commit comments