@@ -52,26 +52,25 @@ def test_quantile_sparse(self, df, expected):
52
52
53
53
tm .assert_series_equal (result , expected )
54
54
55
- @pytest .mark .filterwarnings ("ignore:In future versions of pandas, numeric_only" )
56
55
def test_quantile (self , datetime_frame ):
57
56
from numpy import percentile
58
57
59
58
df = datetime_frame
60
- q = df .quantile (0.1 , axis = 0 )
59
+ q = df .quantile (0.1 , axis = 0 , numeric_only = True )
61
60
assert q ["A" ] == percentile (df ["A" ], 10 )
62
61
tm .assert_index_equal (q .index , df .columns )
63
62
64
- q = df .quantile (0.9 , axis = 1 )
63
+ q = df .quantile (0.9 , axis = 1 , numeric_only = True )
65
64
assert q ["2000-01-17" ] == percentile (df .loc ["2000-01-17" ], 90 )
66
65
tm .assert_index_equal (q .index , df .index )
67
66
68
67
# test degenerate case
69
- q = DataFrame ({"x" : [], "y" : []}).quantile (0.1 , axis = 0 )
68
+ q = DataFrame ({"x" : [], "y" : []}).quantile (0.1 , axis = 0 , numeric_only = True )
70
69
assert np .isnan (q ["x" ]) and np .isnan (q ["y" ])
71
70
72
71
# non-numeric exclusion
73
72
df = DataFrame ({"col1" : ["A" , "A" , "B" , "B" ], "col2" : [1 , 2 , 3 , 4 ]})
74
- rs = df .quantile (0.5 )
73
+ rs = df .quantile (0.5 , numeric_only = True )
75
74
with tm .assert_produces_warning (FutureWarning , match = "Select only valid" ):
76
75
xp = df .median ().rename (0.5 )
77
76
tm .assert_series_equal (rs , xp )
@@ -92,7 +91,7 @@ def test_quantile(self, datetime_frame):
92
91
# so that we exclude non-numeric along the same axis
93
92
# See GH #7312
94
93
df = DataFrame ([[1 , 2 , 3 ], ["a" , "b" , 4 ]])
95
- result = df .quantile (0.5 , axis = 1 )
94
+ result = df .quantile (0.5 , axis = 1 , numeric_only = True )
96
95
expected = Series ([3.0 , 4.0 ], index = [0 , 1 ], name = 0.5 )
97
96
tm .assert_series_equal (result , expected )
98
97
@@ -121,7 +120,7 @@ def test_quantile_axis_mixed(self):
121
120
"D" : ["foo" , "bar" , "baz" ],
122
121
}
123
122
)
124
- result = df .quantile (0.5 , axis = 1 )
123
+ result = df .quantile (0.5 , axis = 1 , numeric_only = True )
125
124
expected = Series ([1.5 , 2.5 , 3.5 ], name = 0.5 )
126
125
tm .assert_series_equal (result , expected )
127
126
@@ -158,7 +157,6 @@ def test_quantile_axis_parameter(self):
158
157
with pytest .raises (ValueError , match = msg ):
159
158
df .quantile (0.1 , axis = "column" )
160
159
161
- @pytest .mark .filterwarnings ("ignore:In future versions of pandas, numeric_only" )
162
160
def test_quantile_interpolation (self ):
163
161
# see gh-10174
164
162
@@ -221,7 +219,7 @@ def test_quantile_interpolation_datetime(self, datetime_frame):
221
219
222
220
# interpolation = linear (default case)
223
221
df = datetime_frame
224
- q = df .quantile (0.1 , axis = 0 , interpolation = "linear" )
222
+ q = df .quantile (0.1 , axis = 0 , numeric_only = True , interpolation = "linear" )
225
223
assert q ["A" ] == np .percentile (df ["A" ], 10 )
226
224
227
225
def test_quantile_interpolation_int (self , int_frame ):
@@ -264,7 +262,7 @@ def test_quantile_datetime(self):
264
262
df = DataFrame ({"a" : pd .to_datetime (["2010" , "2011" ]), "b" : [0 , 5 ]})
265
263
266
264
# exclude datetime
267
- result = df .quantile (0.5 )
265
+ result = df .quantile (0.5 , numeric_only = True )
268
266
expected = Series ([2.5 ], index = ["b" ])
269
267
270
268
# datetime
@@ -300,11 +298,11 @@ def test_quantile_datetime(self):
300
298
tm .assert_frame_equal (result , expected )
301
299
302
300
# empty when numeric_only=True
303
- result = df [["a" , "c" ]].quantile (0.5 )
301
+ result = df [["a" , "c" ]].quantile (0.5 , numeric_only = True )
304
302
expected = Series ([], index = [], dtype = np .float64 , name = 0.5 )
305
303
tm .assert_series_equal (result , expected )
306
304
307
- result = df [["a" , "c" ]].quantile ([0.5 ])
305
+ result = df [["a" , "c" ]].quantile ([0.5 ], numeric_only = True )
308
306
expected = DataFrame (index = [0.5 ])
309
307
tm .assert_frame_equal (result , expected )
310
308
@@ -582,12 +580,12 @@ def test_quantile_empty_no_columns(self):
582
580
# GH#23925 _get_numeric_data may drop all columns
583
581
df = DataFrame (pd .date_range ("1/1/18" , periods = 5 ))
584
582
df .columns .name = "captain tightpants"
585
- result = df .quantile (0.5 )
583
+ result = df .quantile (0.5 , numeric_only = True )
586
584
expected = Series ([], index = [], name = 0.5 , dtype = np .float64 )
587
585
expected .index .name = "captain tightpants"
588
586
tm .assert_series_equal (result , expected )
589
587
590
- result = df .quantile ([0.5 ])
588
+ result = df .quantile ([0.5 ], numeric_only = True )
591
589
expected = DataFrame ([], index = [0.5 ], columns = [])
592
590
expected .columns .name = "captain tightpants"
593
591
tm .assert_frame_equal (result , expected )
@@ -778,7 +776,7 @@ def test_datelike_numeric_only(self, expected_data, expected_index, axis):
778
776
"c" : pd .to_datetime (["2011" , "2012" ]),
779
777
}
780
778
)
781
- result = df [["a" , "c" ]].quantile (0.5 , axis = axis )
779
+ result = df [["a" , "c" ]].quantile (0.5 , axis = axis , numeric_only = True )
782
780
expected = Series (
783
781
expected_data , name = 0.5 , index = Index (expected_index ), dtype = np .float64
784
782
)
0 commit comments