@@ -48,41 +48,40 @@ def test_numeric_only_default_false_warning(self):
48
48
def test_quantile_sparse (self , df , expected ):
49
49
# GH#17198
50
50
# GH#24600
51
- result = df .quantile ()
51
+ result = df .quantile (numeric_only = True )
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 , numeric_only = True , axis = 0 )
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 )
78
77
79
78
# axis
80
79
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 )
82
81
expected = Series ([1.5 , 2.5 , 3.5 ], index = [1 , 2 , 3 ], name = 0.5 )
83
82
tm .assert_series_equal (result , expected )
84
83
85
- result = df .quantile ([0.5 , 0.75 ], axis = 1 )
84
+ result = df .quantile ([0.5 , 0.75 ], numeric_only = True , axis = 1 )
86
85
expected = DataFrame (
87
86
{1 : [1.5 , 1.75 ], 2 : [2.5 , 2.75 ], 3 : [3.5 , 3.75 ]}, index = [0.5 , 0.75 ]
88
87
)
@@ -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 , numeric_only = True , axis = 1 )
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 , numeric_only = True , axis = 1 )
125
124
expected = Series ([1.5 , 2.5 , 3.5 ], name = 0.5 )
126
125
tm .assert_series_equal (result , expected )
127
126
@@ -135,36 +134,35 @@ def test_quantile_axis_parameter(self):
135
134
136
135
df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
137
136
138
- result = df .quantile (0.5 , axis = 0 )
137
+ result = df .quantile (0.5 , axis = 0 , numeric_only = True )
139
138
140
139
expected = Series ([2.0 , 3.0 ], index = ["A" , "B" ], name = 0.5 )
141
140
tm .assert_series_equal (result , expected )
142
141
143
- expected = df .quantile (0.5 , axis = "index" )
142
+ expected = df .quantile (0.5 , axis = "index" , numeric_only = True )
144
143
tm .assert_series_equal (result , expected )
145
144
146
- result = df .quantile (0.5 , axis = 1 )
145
+ result = df .quantile (0.5 , axis = 1 , numeric_only = True )
147
146
148
147
expected = Series ([1.5 , 2.5 , 3.5 ], index = [1 , 2 , 3 ], name = 0.5 )
149
148
tm .assert_series_equal (result , expected )
150
149
151
- result = df .quantile (0.5 , axis = "columns" )
150
+ result = df .quantile (0.5 , axis = "columns" , numeric_only = True )
152
151
tm .assert_series_equal (result , expected )
153
152
154
153
msg = "No axis named -1 for object type DataFrame"
155
154
with pytest .raises (ValueError , match = msg ):
156
- df .quantile (0.1 , axis = - 1 )
155
+ df .quantile (0.1 , axis = - 1 , numeric_only = True )
157
156
msg = "No axis named column for object type DataFrame"
158
157
with pytest .raises (ValueError , match = msg ):
159
- df .quantile (0.1 , axis = "column" )
158
+ df .quantile (0.1 , axis = "column" , numeric_only = True )
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
165
163
# interpolation method other than default linear
166
164
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" )
168
166
expected = Series ([1 , 2 , 3 ], index = [1 , 2 , 3 ], name = 0.5 )
169
167
tm .assert_series_equal (result , expected )
170
168
@@ -180,7 +178,7 @@ def test_quantile_interpolation(self):
180
178
181
179
# float
182
180
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" )
184
182
expected = Series ([1.0 , 2.0 , 3.0 ], index = [1 , 2 , 3 ], name = 0.5 )
185
183
tm .assert_series_equal (result , expected )
186
184
exp = np .percentile (
@@ -193,20 +191,22 @@ def test_quantile_interpolation(self):
193
191
tm .assert_series_equal (result , expected )
194
192
195
193
# 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
+ )
197
197
expected = DataFrame (
198
198
{1 : [1.0 , 1.0 ], 2 : [2.0 , 2.0 ], 3 : [3.0 , 3.0 ]}, index = [0.5 , 0.75 ]
199
199
)
200
200
tm .assert_frame_equal (result , expected )
201
201
202
202
# test degenerate case
203
203
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" )
205
205
assert np .isnan (q ["x" ]) and np .isnan (q ["y" ])
206
206
207
207
# multi
208
208
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" )
210
210
211
211
# https://github.com/numpy/numpy/issues/7163
212
212
expected = DataFrame (
@@ -221,25 +221,25 @@ def test_quantile_interpolation_datetime(self, datetime_frame):
221
221
222
222
# interpolation = linear (default case)
223
223
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" )
225
225
assert q ["A" ] == np .percentile (df ["A" ], 10 )
226
226
227
227
def test_quantile_interpolation_int (self , int_frame ):
228
228
# see gh-10174
229
229
230
230
df = int_frame
231
231
# interpolation = linear (default case)
232
- q = df .quantile (0.1 )
232
+ q = df .quantile (0.1 , numeric_only = True )
233
233
assert q ["A" ] == np .percentile (df ["A" ], 10 )
234
234
235
235
# 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" )
237
237
assert q1 ["A" ] == np .percentile (df ["A" ], 10 )
238
238
tm .assert_series_equal (q , q1 )
239
239
240
240
def test_quantile_multi (self ):
241
241
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 )
243
243
expected = DataFrame (
244
244
[[1.5 , 1.5 , 1.5 ], [2.0 , 2.0 , 2.0 ]],
245
245
index = [0.25 , 0.5 ],
@@ -248,13 +248,15 @@ def test_quantile_multi(self):
248
248
tm .assert_frame_equal (result , expected )
249
249
250
250
# 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 )
252
252
expected = DataFrame (
253
253
[[1.5 , 1.5 , 1.5 ], [2.0 , 2.0 , 2.0 ]], index = [0.25 , 0.5 ], columns = [0 , 1 , 2 ]
254
254
)
255
255
256
256
# 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
+ )
258
260
expected = DataFrame (
259
261
{"x" : [np .nan , np .nan ], "y" : [np .nan , np .nan ]}, index = [0.1 , 0.9 ]
260
262
)
@@ -265,7 +267,7 @@ def test_quantile_datetime(self):
265
267
df = DataFrame ({"a" : pd .to_datetime (["2010" , "2011" ]), "b" : [0 , 5 ]})
266
268
267
269
# exclude datetime
268
- result = df .quantile (0.5 )
270
+ result = df .quantile (0.5 , numeric_only = True )
269
271
expected = Series ([2.5 ], index = ["b" ])
270
272
271
273
# datetime
@@ -301,11 +303,11 @@ def test_quantile_datetime(self):
301
303
tm .assert_frame_equal (result , expected )
302
304
303
305
# empty when numeric_only=True
304
- result = df [["a" , "c" ]].quantile (0.5 )
306
+ result = df [["a" , "c" ]].quantile (0.5 , numeric_only = True )
305
307
expected = Series ([], index = [], dtype = np .float64 , name = 0.5 )
306
308
tm .assert_series_equal (result , expected )
307
309
308
- result = df [["a" , "c" ]].quantile ([0.5 ])
310
+ result = df [["a" , "c" ]].quantile ([0.5 ], numeric_only = True )
309
311
expected = DataFrame (index = [0.5 ])
310
312
tm .assert_frame_equal (result , expected )
311
313
@@ -468,30 +470,30 @@ def test_quantile_nan(self):
468
470
df = DataFrame ({"a" : np .arange (1 , 6.0 ), "b" : np .arange (1 , 6.0 )})
469
471
df .iloc [- 1 , 1 ] = np .nan
470
472
471
- res = df .quantile (0.5 )
473
+ res = df .quantile (0.5 , numeric_only = True )
472
474
exp = Series ([3.0 , 2.5 ], index = ["a" , "b" ], name = 0.5 )
473
475
tm .assert_series_equal (res , exp )
474
476
475
- res = df .quantile ([0.5 , 0.75 ])
477
+ res = df .quantile ([0.5 , 0.75 ], numeric_only = True )
476
478
exp = DataFrame ({"a" : [3.0 , 4.0 ], "b" : [2.5 , 3.25 ]}, index = [0.5 , 0.75 ])
477
479
tm .assert_frame_equal (res , exp )
478
480
479
- res = df .quantile (0.5 , axis = 1 )
481
+ res = df .quantile (0.5 , axis = 1 , numeric_only = True )
480
482
exp = Series (np .arange (1.0 , 6.0 ), name = 0.5 )
481
483
tm .assert_series_equal (res , exp )
482
484
483
- res = df .quantile ([0.5 , 0.75 ], axis = 1 )
485
+ res = df .quantile ([0.5 , 0.75 ], axis = 1 , numeric_only = True )
484
486
exp = DataFrame ([np .arange (1.0 , 6.0 )] * 2 , index = [0.5 , 0.75 ])
485
487
tm .assert_frame_equal (res , exp )
486
488
487
489
# full-nan column
488
490
df ["b" ] = np .nan
489
491
490
- res = df .quantile (0.5 )
492
+ res = df .quantile (0.5 , numeric_only = True )
491
493
exp = Series ([3.0 , np .nan ], index = ["a" , "b" ], name = 0.5 )
492
494
tm .assert_series_equal (res , exp )
493
495
494
- res = df .quantile ([0.5 , 0.75 ])
496
+ res = df .quantile ([0.5 , 0.75 ], numeric_only = True )
495
497
exp = DataFrame ({"a" : [3.0 , 4.0 ], "b" : [np .nan , np .nan ]}, index = [0.5 , 0.75 ])
496
498
tm .assert_frame_equal (res , exp )
497
499
@@ -536,27 +538,27 @@ def test_quantile_empty_no_rows_floats(self):
536
538
# floats
537
539
df = DataFrame (columns = ["a" , "b" ], dtype = "float64" )
538
540
539
- res = df .quantile (0.5 )
541
+ res = df .quantile (0.5 , numeric_only = True )
540
542
exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
541
543
tm .assert_series_equal (res , exp )
542
544
543
- res = df .quantile ([0.5 ])
545
+ res = df .quantile ([0.5 ], numeric_only = True )
544
546
exp = DataFrame ([[np .nan , np .nan ]], columns = ["a" , "b" ], index = [0.5 ])
545
547
tm .assert_frame_equal (res , exp )
546
548
547
- res = df .quantile (0.5 , axis = 1 )
549
+ res = df .quantile (0.5 , axis = 1 , numeric_only = True )
548
550
exp = Series ([], index = [], dtype = "float64" , name = 0.5 )
549
551
tm .assert_series_equal (res , exp )
550
552
551
- res = df .quantile ([0.5 ], axis = 1 )
553
+ res = df .quantile ([0.5 ], axis = 1 , numeric_only = True )
552
554
exp = DataFrame (columns = [], index = [0.5 ])
553
555
tm .assert_frame_equal (res , exp )
554
556
555
557
def test_quantile_empty_no_rows_ints (self ):
556
558
# ints
557
559
df = DataFrame (columns = ["a" , "b" ], dtype = "int64" )
558
560
559
- res = df .quantile (0.5 )
561
+ res = df .quantile (0.5 , numeric_only = True )
560
562
exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
561
563
tm .assert_series_equal (res , exp )
562
564
@@ -587,12 +589,12 @@ def test_quantile_empty_no_columns(self):
587
589
# GH#23925 _get_numeric_data may drop all columns
588
590
df = DataFrame (pd .date_range ("1/1/18" , periods = 5 ))
589
591
df .columns .name = "captain tightpants"
590
- result = df .quantile (0.5 )
592
+ result = df .quantile (0.5 , numeric_only = True )
591
593
expected = Series ([], index = [], name = 0.5 , dtype = np .float64 )
592
594
expected .index .name = "captain tightpants"
593
595
tm .assert_series_equal (result , expected )
594
596
595
- result = df .quantile ([0.5 ])
597
+ result = df .quantile ([0.5 ], numeric_only = True )
596
598
expected = DataFrame ([], index = [0.5 ], columns = [])
597
599
expected .columns .name = "captain tightpants"
598
600
tm .assert_frame_equal (result , expected )
@@ -743,7 +745,7 @@ def test_quantile_ea_scalar(self, obj, index):
743
745
def test_empty_numeric (self , dtype , expected_data , expected_index , axis ):
744
746
# GH 14564
745
747
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 )
747
749
expected = Series (
748
750
expected_data , name = 0.5 , index = Index (expected_index ), dtype = "float64"
749
751
)
@@ -783,7 +785,7 @@ def test_datelike_numeric_only(self, expected_data, expected_index, axis):
783
785
"c" : pd .to_datetime (["2011" , "2012" ]),
784
786
}
785
787
)
786
- result = df [["a" , "c" ]].quantile (0.5 , axis = axis )
788
+ result = df [["a" , "c" ]].quantile (0.5 , axis = axis , numeric_only = True )
787
789
expected = Series (
788
790
expected_data , name = 0.5 , index = Index (expected_index ), dtype = np .float64
789
791
)
0 commit comments