Skip to content

Commit 4ec92eb

Browse files
makbigcjreback
authored andcommitted
TST/CLN: Fixturize tests/frame/test_quantile.py (#26556)
1 parent 2630a0b commit 4ec92eb

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

pandas/tests/frame/test_quantile.py

+33-23
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33

44
import pandas as pd
55
from pandas import DataFrame, Series, Timestamp
6-
from pandas.tests.frame.common import TestData
76
import pandas.util.testing as tm
87
from pandas.util.testing import assert_frame_equal, assert_series_equal
98

109

11-
class TestDataFrameQuantile(TestData):
10+
class TestDataFrameQuantile:
1211

13-
def test_quantile(self):
12+
def test_quantile(self, datetime_frame):
1413
from numpy import percentile
1514

16-
q = self.tsframe.quantile(0.1, axis=0)
17-
assert q['A'] == percentile(self.tsframe['A'], 10)
18-
tm.assert_index_equal(q.index, self.tsframe.columns)
15+
df = datetime_frame
16+
q = df.quantile(0.1, axis=0)
17+
assert q['A'] == percentile(df['A'], 10)
18+
tm.assert_index_equal(q.index, df.columns)
1919

20-
q = self.tsframe.quantile(0.9, axis=1)
20+
q = df.quantile(0.9, axis=1)
2121
assert (q['2000-01-17'] ==
22-
percentile(self.tsframe.loc['2000-01-17'], 90))
23-
tm.assert_index_equal(q.index, self.tsframe.index)
22+
percentile(df.loc['2000-01-17'], 90))
23+
tm.assert_index_equal(q.index, df.index)
2424

2525
# test degenerate case
2626
q = DataFrame({'x': [], 'y': []}).quantile(0.1, axis=0)
@@ -99,18 +99,6 @@ def test_quantile_axis_parameter(self):
9999

100100
def test_quantile_interpolation(self):
101101
# see gh-10174
102-
from numpy import percentile
103-
104-
# interpolation = linear (default case)
105-
q = self.tsframe.quantile(0.1, axis=0, interpolation='linear')
106-
assert q['A'] == percentile(self.tsframe['A'], 10)
107-
q = self.intframe.quantile(0.1)
108-
assert q['A'] == percentile(self.intframe['A'], 10)
109-
110-
# test with and without interpolation keyword
111-
q1 = self.intframe.quantile(0.1)
112-
assert q1['A'] == np.percentile(self.intframe['A'], 10)
113-
tm.assert_series_equal(q, q1)
114102

115103
# interpolation method other than default linear
116104
df = DataFrame({"A": [1, 2, 3], "B": [2, 3, 4]}, index=[1, 2, 3])
@@ -155,6 +143,28 @@ def test_quantile_interpolation(self):
155143
index=[.25, .5], columns=['a', 'b', 'c'])
156144
assert_frame_equal(result, expected)
157145

146+
def test_quantile_interpolation_datetime(self, datetime_frame):
147+
# see gh-10174
148+
149+
# interpolation = linear (default case)
150+
df = datetime_frame
151+
q = df.quantile(0.1, axis=0, interpolation='linear')
152+
assert q['A'] == np.percentile(df['A'], 10)
153+
154+
def test_quantile_interpolation_int(self, int_frame):
155+
# see gh-10174
156+
157+
df = int_frame
158+
# interpolation = linear (default case)
159+
q = df.quantile(0.1)
160+
assert q['A'] == np.percentile(df['A'], 10)
161+
162+
# test with and without interpolation keyword
163+
# TODO: q1 is not different from q
164+
q1 = df.quantile(0.1)
165+
assert q1['A'] == np.percentile(df['A'], 10)
166+
tm.assert_series_equal(q, q1)
167+
158168
def test_quantile_multi(self):
159169
df = DataFrame([[1, 1, 1], [2, 2, 2], [3, 3, 3]],
160170
columns=['a', 'b', 'c'])
@@ -214,11 +224,11 @@ def test_quantile_datetime(self):
214224
# result = df[['a', 'c']].quantile(.5)
215225
# result = df[['a', 'c']].quantile([.5])
216226

217-
def test_quantile_invalid(self):
227+
def test_quantile_invalid(self, datetime_frame):
218228
msg = 'percentiles should all be in the interval \\[0, 1\\]'
219229
for invalid in [-1, 2, [0.5, -1], [0.5, 2]]:
220230
with pytest.raises(ValueError, match=msg):
221-
self.tsframe.quantile(invalid)
231+
datetime_frame.quantile(invalid)
222232

223233
def test_quantile_box(self):
224234
df = DataFrame({'A': [pd.Timestamp('2011-01-01'),

0 commit comments

Comments
 (0)