@@ -82,17 +82,22 @@ def test_missing_minp_zero():
82
82
def test_expanding_axis (axis_frame ):
83
83
# see gh-23372.
84
84
df = DataFrame (np .ones ((10 , 20 )))
85
- axis = df ._get_axis_number (axis_frame )
86
-
85
+ axis = df ._get_axis_number (axis_frame )
87
86
if axis == 0 :
88
87
expected = DataFrame (
89
88
{i : [np .nan ] * 2 + [float (j ) for j in range (3 , 11 )] for i in range (20 )}
90
89
)
90
+ warning_msg = (
91
+ "The 'axis' keyword in DataFrame.expanding is deprecated and "
92
+ "will be removed in a future version."
93
+ )
91
94
else :
92
95
# axis == 1
93
96
expected = DataFrame ([[np .nan ] * 2 + [float (i ) for i in range (3 , 21 )]] * 10 )
97
+ warning_msg = "DataFrame.expanding with axis=1 is deprecated."
94
98
95
- result = df .expanding (3 , axis = axis_frame ).sum ()
99
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
100
+ result = df .expanding (3 , axis = axis_frame ).sum ()
96
101
tm .assert_frame_equal (result , expected )
97
102
98
103
@@ -323,7 +328,12 @@ def test_expanding_corr_pairwise(frame):
323
328
)
324
329
def test_expanding_func (func , static_comp , frame_or_series ):
325
330
data = frame_or_series (np .array (list (range (10 )) + [np .nan ] * 10 ))
326
- result = getattr (data .expanding (min_periods = 1 , axis = 0 ), func )()
331
+ warning_msg = (
332
+ "The 'axis' keyword in DataFrame.expanding is deprecated and "
333
+ "will be removed in a future version."
334
+ )
335
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
336
+ result = getattr (data .expanding (min_periods = 1 , axis = 0 ), func )()
327
337
assert isinstance (result , frame_or_series )
328
338
329
339
expected = static_comp (data [:11 ])
@@ -341,26 +351,36 @@ def test_expanding_func(func, static_comp, frame_or_series):
341
351
def test_expanding_min_periods (func , static_comp ):
342
352
ser = Series (np .random .randn (50 ))
343
353
344
- result = getattr (ser .expanding (min_periods = 30 , axis = 0 ), func )()
354
+ warning_msg = (
355
+ "The 'axis' keyword in DataFrame.expanding is deprecated and "
356
+ "will be removed in a future version."
357
+ )
358
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
359
+ result = getattr (ser .expanding (min_periods = 30 , axis = 0 ), func )()
345
360
assert result [:29 ].isna ().all ()
346
361
tm .assert_almost_equal (result .iloc [- 1 ], static_comp (ser [:50 ]))
347
362
348
363
# min_periods is working correctly
349
- result = getattr (ser .expanding (min_periods = 15 , axis = 0 ), func )()
364
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
365
+ result = getattr (ser .expanding (min_periods = 15 , axis = 0 ), func )()
350
366
assert isna (result .iloc [13 ])
351
367
assert notna (result .iloc [14 ])
352
368
353
369
ser2 = Series (np .random .randn (20 ))
354
- result = getattr (ser2 .expanding (min_periods = 5 , axis = 0 ), func )()
370
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
371
+ result = getattr (ser2 .expanding (min_periods = 5 , axis = 0 ), func )()
355
372
assert isna (result [3 ])
356
373
assert notna (result [4 ])
357
374
358
375
# min_periods=0
359
- result0 = getattr (ser .expanding (min_periods = 0 , axis = 0 ), func )()
360
- result1 = getattr (ser .expanding (min_periods = 1 , axis = 0 ), func )()
376
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
377
+ result0 = getattr (ser .expanding (min_periods = 0 , axis = 0 ), func )()
378
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
379
+ result1 = getattr (ser .expanding (min_periods = 1 , axis = 0 ), func )()
361
380
tm .assert_almost_equal (result0 , result1 )
362
381
363
- result = getattr (ser .expanding (min_periods = 1 , axis = 0 ), func )()
382
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
383
+ result = getattr (ser .expanding (min_periods = 1 , axis = 0 ), func )()
364
384
tm .assert_almost_equal (result .iloc [- 1 ], static_comp (ser [:50 ]))
365
385
366
386
@@ -693,3 +713,17 @@ def test_numeric_only_corr_cov_series(kernel, use_arg, numeric_only, dtype):
693
713
op2 = getattr (expanding2 , kernel )
694
714
expected = op2 (* arg2 , numeric_only = numeric_only )
695
715
tm .assert_series_equal (result , expected )
716
+
717
+ def test_df_expanding_axis_param_depr ():
718
+ df = DataFrame ({"a" : [1 ], "b" : [2 ], "c" : [3 ]})
719
+
720
+ warning_msg = (
721
+ "The 'axis' keyword in DataFrame.expanding is deprecated and "
722
+ "will be removed in a future version."
723
+ )
724
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
725
+ df .expanding (2 , axis = 0 )
726
+
727
+ warning_msg = "DataFrame.expanding with axis=1 is deprecated."
728
+ with tm .assert_produces_warning (FutureWarning , match = warning_msg ):
729
+ df .expanding (2 , axis = 1 )
0 commit comments