|
9 | 9 | from pandas.core.api import value_counts |
10 | 10 | from pandas.core.categorical import Categorical |
11 | 11 | from pandas.core.index import Index, Int64Index, MultiIndex |
| 12 | +from pandas.core.frame import DataFrame |
12 | 13 | from pandas.util.testing import assert_almost_equal |
13 | 14 | import pandas.core.common as com |
14 | 15 |
|
@@ -116,6 +117,23 @@ def test_levels_none(self): |
116 | 117 | 'a', 'c', 'c', 'c']) |
117 | 118 | self.assert_(factor.equals(self.factor)) |
118 | 119 |
|
| 120 | + def test_describe(self): |
| 121 | + # string type |
| 122 | + desc = self.factor.describe() |
| 123 | + expected = DataFrame.from_dict(dict(counts=[3, 2, 3], |
| 124 | + freqs=[3/8., 2/8., 3/8.], |
| 125 | + levels=['a', 'b', 'c']) |
| 126 | + ).set_index('levels') |
| 127 | + tm.assert_frame_equal(desc, expected) |
| 128 | + |
| 129 | + # check an integer one |
| 130 | + desc = Categorical([1,2,3,1,2,3,3,2,1,1,1]).describe() |
| 131 | + expected = DataFrame.from_dict(dict(counts=[5, 3, 3], |
| 132 | + freqs=[5/11., 3/11., 3/11.], |
| 133 | + levels=[1,2,3] |
| 134 | + ) |
| 135 | + ).set_index('levels') |
| 136 | + tm.assert_frame_equal(desc, expected) |
119 | 137 |
|
120 | 138 | if __name__ == '__main__': |
121 | 139 | import nose |
|
0 commit comments