|
3 | 3 |
|
4 | 4 | import pandas as pd
|
5 | 5 | from pandas import DataFrame, Series, Timestamp
|
6 |
| -from pandas.tests.frame.common import TestData |
7 | 6 | import pandas.util.testing as tm
|
8 | 7 | from pandas.util.testing import assert_frame_equal, assert_series_equal
|
9 | 8 |
|
10 | 9 |
|
11 |
| -class TestDataFrameQuantile(TestData): |
| 10 | +class TestDataFrameQuantile(): |
12 | 11 |
|
13 |
| - def test_quantile(self): |
| 12 | + def test_quantile(self, datetime_frame): |
14 | 13 | from numpy import percentile
|
15 | 14 |
|
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 | + q = datetime_frame.quantile(0.1, axis=0) |
| 16 | + assert q['A'] == percentile(datetime_frame['A'], 10) |
| 17 | + tm.assert_index_equal(q.index, datetime_frame.columns) |
19 | 18 |
|
20 |
| - q = self.tsframe.quantile(0.9, axis=1) |
| 19 | + q = datetime_frame.quantile(0.9, axis=1) |
21 | 20 | assert (q['2000-01-17'] ==
|
22 |
| - percentile(self.tsframe.loc['2000-01-17'], 90)) |
23 |
| - tm.assert_index_equal(q.index, self.tsframe.index) |
| 21 | + percentile(datetime_frame.loc['2000-01-17'], 90)) |
| 22 | + tm.assert_index_equal(q.index, datetime_frame.index) |
24 | 23 |
|
25 | 24 | # test degenerate case
|
26 | 25 | q = DataFrame({'x': [], 'y': []}).quantile(0.1, axis=0)
|
@@ -97,19 +96,19 @@ def test_quantile_axis_parameter(self):
|
97 | 96 | with pytest.raises(ValueError, match=msg):
|
98 | 97 | df.quantile(0.1, axis="column")
|
99 | 98 |
|
100 |
| - def test_quantile_interpolation(self): |
| 99 | + def test_quantile_interpolation(self, datetime_frame, int_frame): |
101 | 100 | # see gh-10174
|
102 | 101 | from numpy import percentile
|
103 | 102 |
|
104 | 103 | # 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) |
| 104 | + q = datetime_frame.quantile(0.1, axis=0, interpolation='linear') |
| 105 | + assert q['A'] == percentile(datetime_frame['A'], 10) |
| 106 | + q = int_frame.quantile(0.1) |
| 107 | + assert q['A'] == percentile(int_frame['A'], 10) |
109 | 108 |
|
110 | 109 | # test with and without interpolation keyword
|
111 |
| - q1 = self.intframe.quantile(0.1) |
112 |
| - assert q1['A'] == np.percentile(self.intframe['A'], 10) |
| 110 | + q1 = int_frame.quantile(0.1) |
| 111 | + assert q1['A'] == np.percentile(int_frame['A'], 10) |
113 | 112 | tm.assert_series_equal(q, q1)
|
114 | 113 |
|
115 | 114 | # interpolation method other than default linear
|
@@ -214,11 +213,11 @@ def test_quantile_datetime(self):
|
214 | 213 | # result = df[['a', 'c']].quantile(.5)
|
215 | 214 | # result = df[['a', 'c']].quantile([.5])
|
216 | 215 |
|
217 |
| - def test_quantile_invalid(self): |
| 216 | + def test_quantile_invalid(self, datetime_frame): |
218 | 217 | msg = 'percentiles should all be in the interval \\[0, 1\\]'
|
219 | 218 | for invalid in [-1, 2, [0.5, -1], [0.5, 2]]:
|
220 | 219 | with pytest.raises(ValueError, match=msg):
|
221 |
| - self.tsframe.quantile(invalid) |
| 220 | + datetime_frame.quantile(invalid) |
222 | 221 |
|
223 | 222 | def test_quantile_box(self):
|
224 | 223 | df = DataFrame({'A': [pd.Timestamp('2011-01-01'),
|
|
0 commit comments