|
31 | 31 | import pandas.core.common as com
|
32 | 32 | import pandas.core.format as fmt
|
33 | 33 | import pandas.core.datetools as datetools
|
34 |
| -from pandas import (DataFrame, Index, Series, notnull, isnull, |
| 34 | +from pandas import (DataFrame, Index, Series, Panel, notnull, isnull, |
35 | 35 | MultiIndex, DatetimeIndex, Timestamp, date_range,
|
36 | 36 | read_csv, timedelta_range, Timedelta,
|
37 | 37 | option_context)
|
@@ -14057,6 +14057,26 @@ def test_assign_bad(self):
|
14057 | 14057 | with tm.assertRaises(KeyError):
|
14058 | 14058 | df.assign(C=df.A, D=lambda x: x['A'] + x['C'])
|
14059 | 14059 |
|
| 14060 | + def test_to_panel_expanddim(self): |
| 14061 | + |
| 14062 | + class SubclassedFrame(DataFrame): |
| 14063 | + @property |
| 14064 | + def _constructor_expanddim(self): |
| 14065 | + return SubclassedPanel |
| 14066 | + |
| 14067 | + class SubclassedPanel(Panel): |
| 14068 | + pass |
| 14069 | + |
| 14070 | + index = MultiIndex.from_tuples([(0, 0), (0, 1), (0, 2)]) |
| 14071 | + df = SubclassedFrame({'X':[1, 2, 3], 'Y': [4, 5, 6]}, index=index) |
| 14072 | + result = df.to_panel() |
| 14073 | + self.assertTrue(isinstance(result, SubclassedPanel)) |
| 14074 | + expected = SubclassedPanel([[[1, 2, 3]], [[4, 5, 6]]], |
| 14075 | + items=['X', 'Y'], major_axis=[0], |
| 14076 | + minor_axis=[0, 1, 2]) |
| 14077 | + tm.assert_panel_equal(result, expected) |
| 14078 | + |
| 14079 | + |
14060 | 14080 | def skip_if_no_ne(engine='numexpr'):
|
14061 | 14081 | if engine == 'numexpr':
|
14062 | 14082 | try:
|
|
0 commit comments