@@ -48,41 +48,40 @@ def test_numeric_only_default_false_warning(self):
4848 def test_quantile_sparse (self , df , expected ):
4949 # GH#17198
5050 # GH#24600
51- result = df .quantile ()
51+ result = df .quantile (numeric_only = True )
5252
5353 tm .assert_series_equal (result , expected )
5454
55- @pytest .mark .filterwarnings ("ignore:In future versions of pandas, numeric_only" )
5655 def test_quantile (self , datetime_frame ):
5756 from numpy import percentile
5857
5958 df = datetime_frame
60- q = df .quantile (0.1 , axis = 0 )
59+ q = df .quantile (0.1 , axis = 0 , numeric_only = True )
6160 assert q ["A" ] == percentile (df ["A" ], 10 )
6261 tm .assert_index_equal (q .index , df .columns )
6362
64- q = df .quantile (0.9 , axis = 1 )
63+ q = df .quantile (0.9 , axis = 1 , numeric_only = True )
6564 assert q ["2000-01-17" ] == percentile (df .loc ["2000-01-17" ], 90 )
6665 tm .assert_index_equal (q .index , df .index )
6766
6867 # test degenerate case
69- q = DataFrame ({"x" : [], "y" : []}).quantile (0.1 , axis = 0 )
68+ q = DataFrame ({"x" : [], "y" : []}).quantile (0.1 , numeric_only = True , axis = 0 )
7069 assert np .isnan (q ["x" ]) and np .isnan (q ["y" ])
7170
7271 # non-numeric exclusion
7372 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 )
7574 with tm .assert_produces_warning (FutureWarning , match = "Select only valid" ):
7675 xp = df .median ().rename (0.5 )
7776 tm .assert_series_equal (rs , xp )
7877
7978 # axis
8079 df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
81- result = df .quantile (0.5 , axis = 1 )
80+ result = df .quantile (0.5 , axis = 1 , numeric_only = True )
8281 expected = Series ([1.5 , 2.5 , 3.5 ], index = [1 , 2 , 3 ], name = 0.5 )
8382 tm .assert_series_equal (result , expected )
8483
85- result = df .quantile ([0.5 , 0.75 ], axis = 1 )
84+ result = df .quantile ([0.5 , 0.75 ], numeric_only = True , axis = 1 )
8685 expected = DataFrame (
8786 {1 : [1.5 , 1.75 ], 2 : [2.5 , 2.75 ], 3 : [3.5 , 3.75 ]}, index = [0.5 , 0.75 ]
8887 )
@@ -92,7 +91,7 @@ def test_quantile(self, datetime_frame):
9291 # so that we exclude non-numeric along the same axis
9392 # See GH #7312
9493 df = DataFrame ([[1 , 2 , 3 ], ["a" , "b" , 4 ]])
95- result = df .quantile (0.5 , axis = 1 )
94+ result = df .quantile (0.5 , numeric_only = True , axis = 1 )
9695 expected = Series ([3.0 , 4.0 ], index = [0 , 1 ], name = 0.5 )
9796 tm .assert_series_equal (result , expected )
9897
@@ -121,7 +120,7 @@ def test_quantile_axis_mixed(self):
121120 "D" : ["foo" , "bar" , "baz" ],
122121 }
123122 )
124- result = df .quantile (0.5 , axis = 1 )
123+ result = df .quantile (0.5 , numeric_only = True , axis = 1 )
125124 expected = Series ([1.5 , 2.5 , 3.5 ], name = 0.5 )
126125 tm .assert_series_equal (result , expected )
127126
@@ -135,36 +134,35 @@ def test_quantile_axis_parameter(self):
135134
136135 df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
137136
138- result = df .quantile (0.5 , axis = 0 )
137+ result = df .quantile (0.5 , axis = 0 , numeric_only = True )
139138
140139 expected = Series ([2.0 , 3.0 ], index = ["A" , "B" ], name = 0.5 )
141140 tm .assert_series_equal (result , expected )
142141
143- expected = df .quantile (0.5 , axis = "index" )
142+ expected = df .quantile (0.5 , axis = "index" , numeric_only = True )
144143 tm .assert_series_equal (result , expected )
145144
146- result = df .quantile (0.5 , axis = 1 )
145+ result = df .quantile (0.5 , axis = 1 , numeric_only = True )
147146
148147 expected = Series ([1.5 , 2.5 , 3.5 ], index = [1 , 2 , 3 ], name = 0.5 )
149148 tm .assert_series_equal (result , expected )
150149
151- result = df .quantile (0.5 , axis = "columns" )
150+ result = df .quantile (0.5 , axis = "columns" , numeric_only = True )
152151 tm .assert_series_equal (result , expected )
153152
154153 msg = "No axis named -1 for object type DataFrame"
155154 with pytest .raises (ValueError , match = msg ):
156- df .quantile (0.1 , axis = - 1 )
155+ df .quantile (0.1 , axis = - 1 , numeric_only = True )
157156 msg = "No axis named column for object type DataFrame"
158157 with pytest .raises (ValueError , match = msg ):
159- df .quantile (0.1 , axis = "column" )
158+ df .quantile (0.1 , axis = "column" , numeric_only = True )
160159
161- @pytest .mark .filterwarnings ("ignore:In future versions of pandas, numeric_only" )
162160 def test_quantile_interpolation (self ):
163161 # see gh-10174
164162
165163 # interpolation method other than default linear
166164 df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
167- result = df .quantile (0.5 , axis = 1 , interpolation = "nearest" )
165+ result = df .quantile (0.5 , axis = 1 , numeric_only = True , interpolation = "nearest" )
168166 expected = Series ([1 , 2 , 3 ], index = [1 , 2 , 3 ], name = 0.5 )
169167 tm .assert_series_equal (result , expected )
170168
@@ -180,7 +178,7 @@ def test_quantile_interpolation(self):
180178
181179 # float
182180 df = DataFrame ({"A" : [1.0 , 2.0 , 3.0 ], "B" : [2.0 , 3.0 , 4.0 ]}, index = [1 , 2 , 3 ])
183- result = df .quantile (0.5 , axis = 1 , interpolation = "nearest" )
181+ result = df .quantile (0.5 , axis = 1 , numeric_only = True , interpolation = "nearest" )
184182 expected = Series ([1.0 , 2.0 , 3.0 ], index = [1 , 2 , 3 ], name = 0.5 )
185183 tm .assert_series_equal (result , expected )
186184 exp = np .percentile (
@@ -193,20 +191,22 @@ def test_quantile_interpolation(self):
193191 tm .assert_series_equal (result , expected )
194192
195193 # axis
196- result = df .quantile ([0.5 , 0.75 ], axis = 1 , interpolation = "lower" )
194+ result = df .quantile (
195+ [0.5 , 0.75 ], axis = 1 , numeric_only = True , interpolation = "lower"
196+ )
197197 expected = DataFrame (
198198 {1 : [1.0 , 1.0 ], 2 : [2.0 , 2.0 ], 3 : [3.0 , 3.0 ]}, index = [0.5 , 0.75 ]
199199 )
200200 tm .assert_frame_equal (result , expected )
201201
202202 # test degenerate case
203203 df = DataFrame ({"x" : [], "y" : []})
204- q = df .quantile (0.1 , axis = 0 , interpolation = "higher" )
204+ q = df .quantile (0.1 , axis = 0 , numeric_only = True , interpolation = "higher" )
205205 assert np .isnan (q ["x" ]) and np .isnan (q ["y" ])
206206
207207 # multi
208208 df = DataFrame ([[1 , 1 , 1 ], [2 , 2 , 2 ], [3 , 3 , 3 ]], columns = ["a" , "b" , "c" ])
209- result = df .quantile ([0.25 , 0.5 ], interpolation = "midpoint" )
209+ result = df .quantile ([0.25 , 0.5 ], numeric_only = True , interpolation = "midpoint" )
210210
211211 # https://github.com/numpy/numpy/issues/7163
212212 expected = DataFrame (
@@ -221,25 +221,25 @@ def test_quantile_interpolation_datetime(self, datetime_frame):
221221
222222 # interpolation = linear (default case)
223223 df = datetime_frame
224- q = df .quantile (0.1 , axis = 0 , interpolation = "linear" )
224+ q = df .quantile (0.1 , axis = 0 , numeric_only = True , interpolation = "linear" )
225225 assert q ["A" ] == np .percentile (df ["A" ], 10 )
226226
227227 def test_quantile_interpolation_int (self , int_frame ):
228228 # see gh-10174
229229
230230 df = int_frame
231231 # interpolation = linear (default case)
232- q = df .quantile (0.1 )
232+ q = df .quantile (0.1 , numeric_only = True )
233233 assert q ["A" ] == np .percentile (df ["A" ], 10 )
234234
235235 # test with and without interpolation keyword
236- q1 = df .quantile (0.1 , axis = 0 , interpolation = "linear" )
236+ q1 = df .quantile (0.1 , axis = 0 , numeric_only = True , interpolation = "linear" )
237237 assert q1 ["A" ] == np .percentile (df ["A" ], 10 )
238238 tm .assert_series_equal (q , q1 )
239239
240240 def test_quantile_multi (self ):
241241 df = DataFrame ([[1 , 1 , 1 ], [2 , 2 , 2 ], [3 , 3 , 3 ]], columns = ["a" , "b" , "c" ])
242- result = df .quantile ([0.25 , 0.5 ])
242+ result = df .quantile ([0.25 , 0.5 ], numeric_only = True )
243243 expected = DataFrame (
244244 [[1.5 , 1.5 , 1.5 ], [2.0 , 2.0 , 2.0 ]],
245245 index = [0.25 , 0.5 ],
@@ -248,13 +248,15 @@ def test_quantile_multi(self):
248248 tm .assert_frame_equal (result , expected )
249249
250250 # axis = 1
251- result = df .quantile ([0.25 , 0.5 ], axis = 1 )
251+ result = df .quantile ([0.25 , 0.5 ], numeric_only = True , axis = 1 )
252252 expected = DataFrame (
253253 [[1.5 , 1.5 , 1.5 ], [2.0 , 2.0 , 2.0 ]], index = [0.25 , 0.5 ], columns = [0 , 1 , 2 ]
254254 )
255255
256256 # empty
257- result = DataFrame ({"x" : [], "y" : []}).quantile ([0.1 , 0.9 ], axis = 0 )
257+ result = DataFrame ({"x" : [], "y" : []}).quantile (
258+ [0.1 , 0.9 ], axis = 0 , numeric_only = True
259+ )
258260 expected = DataFrame (
259261 {"x" : [np .nan , np .nan ], "y" : [np .nan , np .nan ]}, index = [0.1 , 0.9 ]
260262 )
@@ -265,7 +267,7 @@ def test_quantile_datetime(self):
265267 df = DataFrame ({"a" : pd .to_datetime (["2010" , "2011" ]), "b" : [0 , 5 ]})
266268
267269 # exclude datetime
268- result = df .quantile (0.5 )
270+ result = df .quantile (0.5 , numeric_only = True )
269271 expected = Series ([2.5 ], index = ["b" ])
270272
271273 # datetime
@@ -301,11 +303,11 @@ def test_quantile_datetime(self):
301303 tm .assert_frame_equal (result , expected )
302304
303305 # empty when numeric_only=True
304- result = df [["a" , "c" ]].quantile (0.5 )
306+ result = df [["a" , "c" ]].quantile (0.5 , numeric_only = True )
305307 expected = Series ([], index = [], dtype = np .float64 , name = 0.5 )
306308 tm .assert_series_equal (result , expected )
307309
308- result = df [["a" , "c" ]].quantile ([0.5 ])
310+ result = df [["a" , "c" ]].quantile ([0.5 ], numeric_only = True )
309311 expected = DataFrame (index = [0.5 ])
310312 tm .assert_frame_equal (result , expected )
311313
@@ -468,30 +470,30 @@ def test_quantile_nan(self):
468470 df = DataFrame ({"a" : np .arange (1 , 6.0 ), "b" : np .arange (1 , 6.0 )})
469471 df .iloc [- 1 , 1 ] = np .nan
470472
471- res = df .quantile (0.5 )
473+ res = df .quantile (0.5 , numeric_only = True )
472474 exp = Series ([3.0 , 2.5 ], index = ["a" , "b" ], name = 0.5 )
473475 tm .assert_series_equal (res , exp )
474476
475- res = df .quantile ([0.5 , 0.75 ])
477+ res = df .quantile ([0.5 , 0.75 ], numeric_only = True )
476478 exp = DataFrame ({"a" : [3.0 , 4.0 ], "b" : [2.5 , 3.25 ]}, index = [0.5 , 0.75 ])
477479 tm .assert_frame_equal (res , exp )
478480
479- res = df .quantile (0.5 , axis = 1 )
481+ res = df .quantile (0.5 , axis = 1 , numeric_only = True )
480482 exp = Series (np .arange (1.0 , 6.0 ), name = 0.5 )
481483 tm .assert_series_equal (res , exp )
482484
483- res = df .quantile ([0.5 , 0.75 ], axis = 1 )
485+ res = df .quantile ([0.5 , 0.75 ], axis = 1 , numeric_only = True )
484486 exp = DataFrame ([np .arange (1.0 , 6.0 )] * 2 , index = [0.5 , 0.75 ])
485487 tm .assert_frame_equal (res , exp )
486488
487489 # full-nan column
488490 df ["b" ] = np .nan
489491
490- res = df .quantile (0.5 )
492+ res = df .quantile (0.5 , numeric_only = True )
491493 exp = Series ([3.0 , np .nan ], index = ["a" , "b" ], name = 0.5 )
492494 tm .assert_series_equal (res , exp )
493495
494- res = df .quantile ([0.5 , 0.75 ])
496+ res = df .quantile ([0.5 , 0.75 ], numeric_only = True )
495497 exp = DataFrame ({"a" : [3.0 , 4.0 ], "b" : [np .nan , np .nan ]}, index = [0.5 , 0.75 ])
496498 tm .assert_frame_equal (res , exp )
497499
@@ -536,27 +538,27 @@ def test_quantile_empty_no_rows_floats(self):
536538 # floats
537539 df = DataFrame (columns = ["a" , "b" ], dtype = "float64" )
538540
539- res = df .quantile (0.5 )
541+ res = df .quantile (0.5 , numeric_only = True )
540542 exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
541543 tm .assert_series_equal (res , exp )
542544
543- res = df .quantile ([0.5 ])
545+ res = df .quantile ([0.5 ], numeric_only = True )
544546 exp = DataFrame ([[np .nan , np .nan ]], columns = ["a" , "b" ], index = [0.5 ])
545547 tm .assert_frame_equal (res , exp )
546548
547- res = df .quantile (0.5 , axis = 1 )
549+ res = df .quantile (0.5 , axis = 1 , numeric_only = True )
548550 exp = Series ([], index = [], dtype = "float64" , name = 0.5 )
549551 tm .assert_series_equal (res , exp )
550552
551- res = df .quantile ([0.5 ], axis = 1 )
553+ res = df .quantile ([0.5 ], axis = 1 , numeric_only = True )
552554 exp = DataFrame (columns = [], index = [0.5 ])
553555 tm .assert_frame_equal (res , exp )
554556
555557 def test_quantile_empty_no_rows_ints (self ):
556558 # ints
557559 df = DataFrame (columns = ["a" , "b" ], dtype = "int64" )
558560
559- res = df .quantile (0.5 )
561+ res = df .quantile (0.5 , numeric_only = True )
560562 exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
561563 tm .assert_series_equal (res , exp )
562564
@@ -587,12 +589,12 @@ def test_quantile_empty_no_columns(self):
587589 # GH#23925 _get_numeric_data may drop all columns
588590 df = DataFrame (pd .date_range ("1/1/18" , periods = 5 ))
589591 df .columns .name = "captain tightpants"
590- result = df .quantile (0.5 )
592+ result = df .quantile (0.5 , numeric_only = True )
591593 expected = Series ([], index = [], name = 0.5 , dtype = np .float64 )
592594 expected .index .name = "captain tightpants"
593595 tm .assert_series_equal (result , expected )
594596
595- result = df .quantile ([0.5 ])
597+ result = df .quantile ([0.5 ], numeric_only = True )
596598 expected = DataFrame ([], index = [0.5 ], columns = [])
597599 expected .columns .name = "captain tightpants"
598600 tm .assert_frame_equal (result , expected )
@@ -743,7 +745,7 @@ def test_quantile_ea_scalar(self, obj, index):
743745 def test_empty_numeric (self , dtype , expected_data , expected_index , axis ):
744746 # GH 14564
745747 df = DataFrame (columns = ["a" , "b" ], dtype = dtype )
746- result = df .quantile (0.5 , axis = axis )
748+ result = df .quantile (0.5 , axis = axis , numeric_only = True )
747749 expected = Series (
748750 expected_data , name = 0.5 , index = Index (expected_index ), dtype = "float64"
749751 )
@@ -783,7 +785,7 @@ def test_datelike_numeric_only(self, expected_data, expected_index, axis):
783785 "c" : pd .to_datetime (["2011" , "2012" ]),
784786 }
785787 )
786- result = df [["a" , "c" ]].quantile (0.5 , axis = axis )
788+ result = df [["a" , "c" ]].quantile (0.5 , axis = axis , numeric_only = True )
787789 expected = Series (
788790 expected_data , name = 0.5 , index = Index (expected_index ), dtype = np .float64
789791 )
0 commit comments