1010
1111class TestDataFramePctChange :
1212 @pytest .mark .parametrize (
13- "periods, fill_method, limit, exp" ,
13+ "periods, exp" ,
1414 [
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 ]),
2317 ],
2418 )
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 ):
2820 vals = [np .nan , np .nan , 1 , 2 , 4 , 10 , np .nan , np .nan ]
2921 obj = frame_or_series (vals )
3022
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 )
3724 tm .assert_equal (res , frame_or_series (exp ))
3825
3926 def test_pct_change_numeric (self ):
@@ -45,124 +32,82 @@ def test_pct_change_numeric(self):
4532 pnl .iat [1 , 1 ] = np .nan
4633 pnl .iat [2 , 3 ] = 60
4734
48- msg = (
49- "The 'fill_method' keyword being not None and the 'limit' keyword in "
50- "DataFrame.pct_change are deprecated"
51- )
52-
5335 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 )
5838 tm .assert_frame_equal (result , expected )
5939
6040 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 ()
6742 tm .assert_frame_equal (rs , datetime_frame / datetime_frame .shift (1 ) - 1 )
6843
6944 rs = datetime_frame .pct_change (2 )
7045 filled = datetime_frame .ffill ()
7146 tm .assert_frame_equal (rs , filled / filled .shift (2 ) - 1 )
7247
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 )
7750
7851 rs = datetime_frame .pct_change (freq = "5D" )
79- filled = datetime_frame .ffill ()
8052 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+ ),
8257 )
8358
8459 def test_pct_change_shift_over_nas (self ):
8560 s = Series ([1.0 , 1.5 , np .nan , 2.5 , 3.0 ])
8661
8762 df = DataFrame ({"a" : s , "b" : s })
8863
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 ])
9466 edf = DataFrame ({"a" : expected , "b" : expected })
9567 tm .assert_frame_equal (chg , edf )
9668
9769 @pytest .mark .parametrize (
98- "freq, periods, fill_method, limit " ,
70+ "freq, periods" ,
9971 [
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 ),
10675 ],
10776 )
10877 def test_pct_change_periods_freq (
109- self , datetime_frame , freq , periods , fill_method , limit
78+ self ,
79+ datetime_frame ,
80+ freq ,
81+ periods ,
11082 ):
111- msg = (
112- "The 'fill_method' keyword being not None and the 'limit' keyword in "
113- "DataFrame.pct_change are deprecated"
114- )
115-
11683 # 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 )
12586 tm .assert_frame_equal (rs_freq , rs_periods )
12687
12788 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 )
13691 tm .assert_frame_equal (rs_freq , rs_periods )
13792
13893
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 ():
14195 # GH30463
14296 data = DataFrame (
14397 {0 : [np .nan , 1 , 2 , 3 , 9 , 18 ], 1 : [0 , 1 , np .nan , 3 , 9 , 18 ]}, index = ["a" , "b" ] * 3
14498 )
14599
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 ()
153101
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 ]
158103 expected = DataFrame (
159104 {0 : [np .nan , np .nan , 1.0 , 0.5 , 2.0 , 1.0 ], 1 : second_column },
160105 index = ["a" , "b" ] * 3 ,
161106 )
162107 tm .assert_frame_equal (result , expected )
163108
164109
165- def test_pct_change_none_beginning_no_warning ():
110+ def test_pct_change_none_beginning ():
166111 # GH#54481
167112 df = DataFrame (
168113 [
0 commit comments