@@ -67,6 +67,7 @@ def assert_stat_op_calc(
67
67
skipna_alternative : function, default None
68
68
NaN-safe version of alternative
69
69
"""
70
+ warn = FutureWarning if opname == "mad" else None
70
71
f = getattr (frame , opname )
71
72
72
73
if check_dates :
@@ -88,8 +89,9 @@ def wrapper(x):
88
89
return alternative (x .values )
89
90
90
91
skipna_wrapper = tm ._make_skipna_wrapper (alternative , skipna_alternative )
91
- result0 = f (axis = 0 , skipna = False )
92
- result1 = f (axis = 1 , skipna = False )
92
+ with tm .assert_produces_warning (warn , match = "The 'mad' method is deprecated" ):
93
+ result0 = f (axis = 0 , skipna = False )
94
+ result1 = f (axis = 1 , skipna = False )
93
95
tm .assert_series_equal (
94
96
result0 , frame .apply (wrapper ), check_dtype = check_dtype , rtol = rtol , atol = atol
95
97
)
@@ -102,8 +104,9 @@ def wrapper(x):
102
104
else :
103
105
skipna_wrapper = alternative
104
106
105
- result0 = f (axis = 0 )
106
- result1 = f (axis = 1 )
107
+ with tm .assert_produces_warning (warn , match = "The 'mad' method is deprecated" ):
108
+ result0 = f (axis = 0 )
109
+ result1 = f (axis = 1 )
107
110
tm .assert_series_equal (
108
111
result0 ,
109
112
frame .apply (skipna_wrapper ),
@@ -125,14 +128,18 @@ def wrapper(x):
125
128
assert lcd_dtype == result1 .dtype
126
129
127
130
# bad axis
128
- with pytest .raises (ValueError , match = "No axis named 2" ):
129
- f (axis = 2 )
131
+ with tm .assert_produces_warning (warn , match = "The 'mad' method is deprecated" ):
132
+ with pytest .raises (ValueError , match = "No axis named 2" ):
133
+ f (axis = 2 )
130
134
131
135
# all NA case
132
136
if has_skipna :
133
137
all_na = frame * np .NaN
134
- r0 = getattr (all_na , opname )(axis = 0 )
135
- r1 = getattr (all_na , opname )(axis = 1 )
138
+ with tm .assert_produces_warning (
139
+ warn , match = "The 'mad' method is deprecated" , raise_on_extra_warnings = False
140
+ ):
141
+ r0 = getattr (all_na , opname )(axis = 0 )
142
+ r1 = getattr (all_na , opname )(axis = 1 )
136
143
if opname in ["sum" , "prod" ]:
137
144
unit = 1 if opname == "prod" else 0 # result for empty sum/prod
138
145
expected = Series (unit , index = r0 .index , dtype = r0 .dtype )
@@ -167,9 +174,13 @@ class TestDataFrameAnalytics:
167
174
],
168
175
)
169
176
def test_stat_op_api_float_string_frame (self , float_string_frame , axis , opname ):
170
- getattr (float_string_frame , opname )(axis = axis )
171
- if opname not in ("nunique" , "mad" ):
172
- getattr (float_string_frame , opname )(axis = axis , numeric_only = True )
177
+ warn = FutureWarning if opname == "mad" else None
178
+ with tm .assert_produces_warning (
179
+ warn , match = "The 'mad' method is deprecated" , raise_on_extra_warnings = False
180
+ ):
181
+ getattr (float_string_frame , opname )(axis = axis )
182
+ if opname not in ("nunique" , "mad" ):
183
+ getattr (float_string_frame , opname )(axis = axis , numeric_only = True )
173
184
174
185
@pytest .mark .filterwarnings ("ignore:Dropping of nuisance:FutureWarning" )
175
186
@pytest .mark .parametrize ("axis" , [0 , 1 ])
@@ -1424,7 +1435,9 @@ def test_frame_any_with_timedelta(self):
1424
1435
def test_reductions_deprecation_skipna_none (self , frame_or_series ):
1425
1436
# GH#44580
1426
1437
obj = frame_or_series ([1 , 2 , 3 ])
1427
- with tm .assert_produces_warning (FutureWarning , match = "skipna" ):
1438
+ with tm .assert_produces_warning (
1439
+ FutureWarning , match = "skipna" , raise_on_extra_warnings = False
1440
+ ):
1428
1441
obj .mad (skipna = None )
1429
1442
1430
1443
def test_reductions_deprecation_level_argument (
@@ -1445,7 +1458,7 @@ def test_reductions_skipna_none_raises(
1445
1458
pytest .mark .xfail (reason = "Count does not accept skipna" )
1446
1459
)
1447
1460
elif reduction_functions == "mad" :
1448
- pytest .skip ("Mad needs a deprecation cycle : GH 11787" )
1461
+ pytest .skip ("Mad is deprecated : GH# 11787" )
1449
1462
obj = frame_or_series ([1 , 2 , 3 ])
1450
1463
msg = 'For argument "skipna" expected type bool, received type NoneType.'
1451
1464
with pytest .raises (ValueError , match = msg ):
@@ -1644,25 +1657,37 @@ def test_mad_nullable_integer(any_signed_int_ea_dtype):
1644
1657
df = DataFrame (np .random .randn (100 , 4 ).astype (np .int64 ))
1645
1658
df2 = df .astype (any_signed_int_ea_dtype )
1646
1659
1647
- result = df2 .mad ()
1648
- expected = df .mad ()
1660
+ with tm .assert_produces_warning (
1661
+ FutureWarning , match = "The 'mad' method is deprecated"
1662
+ ):
1663
+ result = df2 .mad ()
1664
+ expected = df .mad ()
1649
1665
tm .assert_series_equal (result , expected )
1650
1666
1651
- result = df2 .mad (axis = 1 )
1652
- expected = df .mad (axis = 1 )
1667
+ with tm .assert_produces_warning (
1668
+ FutureWarning , match = "The 'mad' method is deprecated"
1669
+ ):
1670
+ result = df2 .mad (axis = 1 )
1671
+ expected = df .mad (axis = 1 )
1653
1672
tm .assert_series_equal (result , expected )
1654
1673
1655
1674
# case with NAs present
1656
1675
df2 .iloc [::2 , 1 ] = pd .NA
1657
1676
1658
- result = df2 .mad ()
1659
- expected = df .mad ()
1660
- expected [1 ] = df .iloc [1 ::2 , 1 ].mad ()
1677
+ with tm .assert_produces_warning (
1678
+ FutureWarning , match = "The 'mad' method is deprecated"
1679
+ ):
1680
+ result = df2 .mad ()
1681
+ expected = df .mad ()
1682
+ expected [1 ] = df .iloc [1 ::2 , 1 ].mad ()
1661
1683
tm .assert_series_equal (result , expected )
1662
1684
1663
- result = df2 .mad (axis = 1 )
1664
- expected = df .mad (axis = 1 )
1665
- expected [::2 ] = df .T .loc [[0 , 2 , 3 ], ::2 ].mad ()
1685
+ with tm .assert_produces_warning (
1686
+ FutureWarning , match = "The 'mad' method is deprecated"
1687
+ ):
1688
+ result = df2 .mad (axis = 1 )
1689
+ expected = df .mad (axis = 1 )
1690
+ expected [::2 ] = df .T .loc [[0 , 2 , 3 ], ::2 ].mad ()
1666
1691
tm .assert_series_equal (result , expected )
1667
1692
1668
1693
@@ -1675,8 +1700,11 @@ def test_mad_nullable_integer_all_na(any_signed_int_ea_dtype):
1675
1700
# case with all-NA row/column
1676
1701
df2 .iloc [:, 1 ] = pd .NA # FIXME(GH#44199): this doesn't operate in-place
1677
1702
df2 .iloc [:, 1 ] = pd .array ([pd .NA ] * len (df2 ), dtype = any_signed_int_ea_dtype )
1678
- result = df2 .mad ()
1679
- expected = df .mad ()
1703
+ with tm .assert_produces_warning (
1704
+ FutureWarning , match = "The 'mad' method is deprecated"
1705
+ ):
1706
+ result = df2 .mad ()
1707
+ expected = df .mad ()
1680
1708
expected [1 ] = pd .NA
1681
1709
expected = expected .astype ("Float64" )
1682
1710
tm .assert_series_equal (result , expected )
0 commit comments