Skip to content

Commit d603c85

Browse files
committed
DEPR: Update tests of quantile with non num cols"
1 parent dfd0448 commit d603c85

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

pandas/tests/frame/methods/test_quantile.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,25 @@ def test_quantile_sparse(self, df, expected):
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, axis=0, numeric_only=True)
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)
@@ -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, axis=1, numeric_only=True)
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, axis=1, numeric_only=True)
125124
expected = Series([1.5, 2.5, 3.5], name=0.5)
126125
tm.assert_series_equal(result, expected)
127126

@@ -158,7 +157,6 @@ def test_quantile_axis_parameter(self):
158157
with pytest.raises(ValueError, match=msg):
159158
df.quantile(0.1, axis="column")
160159

161-
@pytest.mark.filterwarnings("ignore:In future versions of pandas, numeric_only")
162160
def test_quantile_interpolation(self):
163161
# see gh-10174
164162

@@ -221,7 +219,7 @@ def test_quantile_interpolation_datetime(self, datetime_frame):
221219

222220
# interpolation = linear (default case)
223221
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")
225223
assert q["A"] == np.percentile(df["A"], 10)
226224

227225
def test_quantile_interpolation_int(self, int_frame):
@@ -264,7 +262,7 @@ def test_quantile_datetime(self):
264262
df = DataFrame({"a": pd.to_datetime(["2010", "2011"]), "b": [0, 5]})
265263

266264
# exclude datetime
267-
result = df.quantile(0.5)
265+
result = df.quantile(0.5, numeric_only=True)
268266
expected = Series([2.5], index=["b"])
269267

270268
# datetime
@@ -300,11 +298,11 @@ def test_quantile_datetime(self):
300298
tm.assert_frame_equal(result, expected)
301299

302300
# empty when numeric_only=True
303-
result = df[["a", "c"]].quantile(0.5)
301+
result = df[["a", "c"]].quantile(0.5, numeric_only=True)
304302
expected = Series([], index=[], dtype=np.float64, name=0.5)
305303
tm.assert_series_equal(result, expected)
306304

307-
result = df[["a", "c"]].quantile([0.5])
305+
result = df[["a", "c"]].quantile([0.5], numeric_only=True)
308306
expected = DataFrame(index=[0.5])
309307
tm.assert_frame_equal(result, expected)
310308

@@ -582,12 +580,12 @@ def test_quantile_empty_no_columns(self):
582580
# GH#23925 _get_numeric_data may drop all columns
583581
df = DataFrame(pd.date_range("1/1/18", periods=5))
584582
df.columns.name = "captain tightpants"
585-
result = df.quantile(0.5)
583+
result = df.quantile(0.5, numeric_only=True)
586584
expected = Series([], index=[], name=0.5, dtype=np.float64)
587585
expected.index.name = "captain tightpants"
588586
tm.assert_series_equal(result, expected)
589587

590-
result = df.quantile([0.5])
588+
result = df.quantile([0.5], numeric_only=True)
591589
expected = DataFrame([], index=[0.5], columns=[])
592590
expected.columns.name = "captain tightpants"
593591
tm.assert_frame_equal(result, expected)
@@ -778,7 +776,7 @@ def test_datelike_numeric_only(self, expected_data, expected_index, axis):
778776
"c": pd.to_datetime(["2011", "2012"]),
779777
}
780778
)
781-
result = df[["a", "c"]].quantile(0.5, axis=axis)
779+
result = df[["a", "c"]].quantile(0.5, axis=axis, numeric_only=True)
782780
expected = Series(
783781
expected_data, name=0.5, index=Index(expected_index), dtype=np.float64
784782
)

0 commit comments

Comments
 (0)