@@ -48,40 +48,41 @@ 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 (numeric_only = True )
51
+ result = df .quantile ()
52
52
53
53
tm .assert_series_equal (result , expected )
54
54
55
+ @pytest .mark .filterwarnings ("ignore:In future versions of pandas, numeric_only" )
55
56
def test_quantile (self , datetime_frame ):
56
57
from numpy import percentile
57
58
58
59
df = datetime_frame
59
- q = df .quantile (0.1 , axis = 0 , numeric_only = True )
60
+ q = df .quantile (0.1 , axis = 0 )
60
61
assert q ["A" ] == percentile (df ["A" ], 10 )
61
62
tm .assert_index_equal (q .index , df .columns )
62
63
63
- q = df .quantile (0.9 , axis = 1 , numeric_only = True )
64
+ q = df .quantile (0.9 , axis = 1 )
64
65
assert q ["2000-01-17" ] == percentile (df .loc ["2000-01-17" ], 90 )
65
66
tm .assert_index_equal (q .index , df .index )
66
67
67
68
# test degenerate case
68
- q = DataFrame ({"x" : [], "y" : []}).quantile (0.1 , numeric_only = True , axis = 0 )
69
+ q = DataFrame ({"x" : [], "y" : []}).quantile (0.1 , axis = 0 )
69
70
assert np .isnan (q ["x" ]) and np .isnan (q ["y" ])
70
71
71
72
# non-numeric exclusion
72
73
df = DataFrame ({"col1" : ["A" , "A" , "B" , "B" ], "col2" : [1 , 2 , 3 , 4 ]})
73
- rs = df .quantile (0.5 , numeric_only = True )
74
+ rs = df .quantile (0.5 )
74
75
with tm .assert_produces_warning (FutureWarning , match = "Select only valid" ):
75
76
xp = df .median ().rename (0.5 )
76
77
tm .assert_series_equal (rs , xp )
77
78
78
79
# axis
79
80
df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
80
- result = df .quantile (0.5 , axis = 1 , numeric_only = True )
81
+ result = df .quantile (0.5 , axis = 1 )
81
82
expected = Series ([1.5 , 2.5 , 3.5 ], index = [1 , 2 , 3 ], name = 0.5 )
82
83
tm .assert_series_equal (result , expected )
83
84
84
- result = df .quantile ([0.5 , 0.75 ], numeric_only = True , axis = 1 )
85
+ result = df .quantile ([0.5 , 0.75 ], axis = 1 )
85
86
expected = DataFrame (
86
87
{1 : [1.5 , 1.75 ], 2 : [2.5 , 2.75 ], 3 : [3.5 , 3.75 ]}, index = [0.5 , 0.75 ]
87
88
)
@@ -91,7 +92,7 @@ def test_quantile(self, datetime_frame):
91
92
# so that we exclude non-numeric along the same axis
92
93
# See GH #7312
93
94
df = DataFrame ([[1 , 2 , 3 ], ["a" , "b" , 4 ]])
94
- result = df .quantile (0.5 , numeric_only = True , axis = 1 )
95
+ result = df .quantile (0.5 , axis = 1 )
95
96
expected = Series ([3.0 , 4.0 ], index = [0 , 1 ], name = 0.5 )
96
97
tm .assert_series_equal (result , expected )
97
98
@@ -120,7 +121,7 @@ def test_quantile_axis_mixed(self):
120
121
"D" : ["foo" , "bar" , "baz" ],
121
122
}
122
123
)
123
- result = df .quantile (0.5 , numeric_only = True , axis = 1 )
124
+ result = df .quantile (0.5 , axis = 1 )
124
125
expected = Series ([1.5 , 2.5 , 3.5 ], name = 0.5 )
125
126
tm .assert_series_equal (result , expected )
126
127
@@ -134,35 +135,36 @@ def test_quantile_axis_parameter(self):
134
135
135
136
df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
136
137
137
- result = df .quantile (0.5 , axis = 0 , numeric_only = True )
138
+ result = df .quantile (0.5 , axis = 0 )
138
139
139
140
expected = Series ([2.0 , 3.0 ], index = ["A" , "B" ], name = 0.5 )
140
141
tm .assert_series_equal (result , expected )
141
142
142
- expected = df .quantile (0.5 , axis = "index" , numeric_only = True )
143
+ expected = df .quantile (0.5 , axis = "index" )
143
144
tm .assert_series_equal (result , expected )
144
145
145
- result = df .quantile (0.5 , axis = 1 , numeric_only = True )
146
+ result = df .quantile (0.5 , axis = 1 )
146
147
147
148
expected = Series ([1.5 , 2.5 , 3.5 ], index = [1 , 2 , 3 ], name = 0.5 )
148
149
tm .assert_series_equal (result , expected )
149
150
150
- result = df .quantile (0.5 , axis = "columns" , numeric_only = True )
151
+ result = df .quantile (0.5 , axis = "columns" )
151
152
tm .assert_series_equal (result , expected )
152
153
153
154
msg = "No axis named -1 for object type DataFrame"
154
155
with pytest .raises (ValueError , match = msg ):
155
- df .quantile (0.1 , axis = - 1 , numeric_only = True )
156
+ df .quantile (0.1 , axis = - 1 )
156
157
msg = "No axis named column for object type DataFrame"
157
158
with pytest .raises (ValueError , match = msg ):
158
- df .quantile (0.1 , axis = "column" , numeric_only = True )
159
+ df .quantile (0.1 , axis = "column" )
159
160
161
+ @pytest .mark .filterwarnings ("ignore:In future versions of pandas, numeric_only" )
160
162
def test_quantile_interpolation (self ):
161
163
# see gh-10174
162
164
163
165
# interpolation method other than default linear
164
166
df = DataFrame ({"A" : [1 , 2 , 3 ], "B" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
165
- result = df .quantile (0.5 , axis = 1 , numeric_only = True , interpolation = "nearest" )
167
+ result = df .quantile (0.5 , axis = 1 , interpolation = "nearest" )
166
168
expected = Series ([1 , 2 , 3 ], index = [1 , 2 , 3 ], name = 0.5 )
167
169
tm .assert_series_equal (result , expected )
168
170
@@ -178,7 +180,7 @@ def test_quantile_interpolation(self):
178
180
179
181
# float
180
182
df = DataFrame ({"A" : [1.0 , 2.0 , 3.0 ], "B" : [2.0 , 3.0 , 4.0 ]}, index = [1 , 2 , 3 ])
181
- result = df .quantile (0.5 , axis = 1 , numeric_only = True , interpolation = "nearest" )
183
+ result = df .quantile (0.5 , axis = 1 , interpolation = "nearest" )
182
184
expected = Series ([1.0 , 2.0 , 3.0 ], index = [1 , 2 , 3 ], name = 0.5 )
183
185
tm .assert_series_equal (result , expected )
184
186
exp = np .percentile (
@@ -191,22 +193,20 @@ def test_quantile_interpolation(self):
191
193
tm .assert_series_equal (result , expected )
192
194
193
195
# axis
194
- result = df .quantile (
195
- [0.5 , 0.75 ], axis = 1 , numeric_only = True , interpolation = "lower"
196
- )
196
+ result = df .quantile ([0.5 , 0.75 ], axis = 1 , interpolation = "lower" )
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 , numeric_only = True , interpolation = "higher" )
204
+ q = df .quantile (0.1 , axis = 0 , 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 ], numeric_only = True , interpolation = "midpoint" )
209
+ result = df .quantile ([0.25 , 0.5 ], 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 , numeric_only = True , interpolation = "linear" )
224
+ q = df .quantile (0.1 , axis = 0 , 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 , numeric_only = True )
232
+ q = df .quantile (0.1 )
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 , numeric_only = True , interpolation = "linear" )
236
+ q1 = df .quantile (0.1 , axis = 0 , 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 ], numeric_only = True )
242
+ result = df .quantile ([0.25 , 0.5 ])
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,15 +248,13 @@ 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 ], numeric_only = True , axis = 1 )
251
+ result = df .quantile ([0.25 , 0.5 ], 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 (
258
- [0.1 , 0.9 ], axis = 0 , numeric_only = True
259
- )
257
+ result = DataFrame ({"x" : [], "y" : []}).quantile ([0.1 , 0.9 ], axis = 0 )
260
258
expected = DataFrame (
261
259
{"x" : [np .nan , np .nan ], "y" : [np .nan , np .nan ]}, index = [0.1 , 0.9 ]
262
260
)
@@ -266,7 +264,7 @@ def test_quantile_datetime(self):
266
264
df = DataFrame ({"a" : pd .to_datetime (["2010" , "2011" ]), "b" : [0 , 5 ]})
267
265
268
266
# exclude datetime
269
- result = df .quantile (0.5 , numeric_only = True )
267
+ result = df .quantile (0.5 )
270
268
expected = Series ([2.5 ], index = ["b" ])
271
269
272
270
# datetime
@@ -302,11 +300,11 @@ def test_quantile_datetime(self):
302
300
tm .assert_frame_equal (result , expected )
303
301
304
302
# empty when numeric_only=True
305
- result = df [["a" , "c" ]].quantile (0.5 , numeric_only = True )
303
+ result = df [["a" , "c" ]].quantile (0.5 )
306
304
expected = Series ([], index = [], dtype = np .float64 , name = 0.5 )
307
305
tm .assert_series_equal (result , expected )
308
306
309
- result = df [["a" , "c" ]].quantile ([0.5 ], numeric_only = True )
307
+ result = df [["a" , "c" ]].quantile ([0.5 ])
310
308
expected = DataFrame (index = [0.5 ])
311
309
tm .assert_frame_equal (result , expected )
312
310
@@ -467,30 +465,30 @@ def test_quantile_nan(self):
467
465
df = DataFrame ({"a" : np .arange (1 , 6.0 ), "b" : np .arange (1 , 6.0 )})
468
466
df .iloc [- 1 , 1 ] = np .nan
469
467
470
- res = df .quantile (0.5 , numeric_only = True )
468
+ res = df .quantile (0.5 )
471
469
exp = Series ([3.0 , 2.5 ], index = ["a" , "b" ], name = 0.5 )
472
470
tm .assert_series_equal (res , exp )
473
471
474
- res = df .quantile ([0.5 , 0.75 ], numeric_only = True )
472
+ res = df .quantile ([0.5 , 0.75 ])
475
473
exp = DataFrame ({"a" : [3.0 , 4.0 ], "b" : [2.5 , 3.25 ]}, index = [0.5 , 0.75 ])
476
474
tm .assert_frame_equal (res , exp )
477
475
478
- res = df .quantile (0.5 , axis = 1 , numeric_only = True )
476
+ res = df .quantile (0.5 , axis = 1 )
479
477
exp = Series (np .arange (1.0 , 6.0 ), name = 0.5 )
480
478
tm .assert_series_equal (res , exp )
481
479
482
- res = df .quantile ([0.5 , 0.75 ], axis = 1 , numeric_only = True )
480
+ res = df .quantile ([0.5 , 0.75 ], axis = 1 )
483
481
exp = DataFrame ([np .arange (1.0 , 6.0 )] * 2 , index = [0.5 , 0.75 ])
484
482
tm .assert_frame_equal (res , exp )
485
483
486
484
# full-nan column
487
485
df ["b" ] = np .nan
488
486
489
- res = df .quantile (0.5 , numeric_only = True )
487
+ res = df .quantile (0.5 )
490
488
exp = Series ([3.0 , np .nan ], index = ["a" , "b" ], name = 0.5 )
491
489
tm .assert_series_equal (res , exp )
492
490
493
- res = df .quantile ([0.5 , 0.75 ], numeric_only = True )
491
+ res = df .quantile ([0.5 , 0.75 ])
494
492
exp = DataFrame ({"a" : [3.0 , 4.0 ], "b" : [np .nan , np .nan ]}, index = [0.5 , 0.75 ])
495
493
tm .assert_frame_equal (res , exp )
496
494
@@ -534,27 +532,27 @@ def test_quantile_empty_no_rows_floats(self):
534
532
# floats
535
533
df = DataFrame (columns = ["a" , "b" ], dtype = "float64" )
536
534
537
- res = df .quantile (0.5 , numeric_only = True )
535
+ res = df .quantile (0.5 )
538
536
exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
539
537
tm .assert_series_equal (res , exp )
540
538
541
- res = df .quantile ([0.5 ], numeric_only = True )
539
+ res = df .quantile ([0.5 ])
542
540
exp = DataFrame ([[np .nan , np .nan ]], columns = ["a" , "b" ], index = [0.5 ])
543
541
tm .assert_frame_equal (res , exp )
544
542
545
- res = df .quantile (0.5 , axis = 1 , numeric_only = True )
543
+ res = df .quantile (0.5 , axis = 1 )
546
544
exp = Series ([], index = [], dtype = "float64" , name = 0.5 )
547
545
tm .assert_series_equal (res , exp )
548
546
549
- res = df .quantile ([0.5 ], axis = 1 , numeric_only = True )
547
+ res = df .quantile ([0.5 ], axis = 1 )
550
548
exp = DataFrame (columns = [], index = [0.5 ])
551
549
tm .assert_frame_equal (res , exp )
552
550
553
551
def test_quantile_empty_no_rows_ints (self ):
554
552
# ints
555
553
df = DataFrame (columns = ["a" , "b" ], dtype = "int64" )
556
554
557
- res = df .quantile (0.5 , numeric_only = True )
555
+ res = df .quantile (0.5 )
558
556
exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
559
557
tm .assert_series_equal (res , exp )
560
558
@@ -584,12 +582,12 @@ def test_quantile_empty_no_columns(self):
584
582
# GH#23925 _get_numeric_data may drop all columns
585
583
df = DataFrame (pd .date_range ("1/1/18" , periods = 5 ))
586
584
df .columns .name = "captain tightpants"
587
- result = df .quantile (0.5 , numeric_only = True )
585
+ result = df .quantile (0.5 )
588
586
expected = Series ([], index = [], name = 0.5 , dtype = np .float64 )
589
587
expected .index .name = "captain tightpants"
590
588
tm .assert_series_equal (result , expected )
591
589
592
- result = df .quantile ([0.5 ], numeric_only = True )
590
+ result = df .quantile ([0.5 ])
593
591
expected = DataFrame ([], index = [0.5 ], columns = [])
594
592
expected .columns .name = "captain tightpants"
595
593
tm .assert_frame_equal (result , expected )
@@ -740,7 +738,7 @@ def test_quantile_ea_scalar(self, obj, index):
740
738
def test_empty_numeric (self , dtype , expected_data , expected_index , axis ):
741
739
# GH 14564
742
740
df = DataFrame (columns = ["a" , "b" ], dtype = dtype )
743
- result = df .quantile (0.5 , axis = axis , numeric_only = True )
741
+ result = df .quantile (0.5 , axis = axis )
744
742
expected = Series (
745
743
expected_data , name = 0.5 , index = Index (expected_index ), dtype = "float64"
746
744
)
@@ -780,7 +778,7 @@ def test_datelike_numeric_only(self, expected_data, expected_index, axis):
780
778
"c" : pd .to_datetime (["2011" , "2012" ]),
781
779
}
782
780
)
783
- result = df [["a" , "c" ]].quantile (0.5 , axis = axis , numeric_only = True )
781
+ result = df [["a" , "c" ]].quantile (0.5 , axis = axis )
784
782
expected = Series (
785
783
expected_data , name = 0.5 , index = Index (expected_index ), dtype = np .float64
786
784
)
0 commit comments