|
10 | 10 | import numpy as np
|
11 | 11 |
|
12 | 12 | from pandas.compat import lrange, lzip, u
|
13 |
| -from pandas import (compat, DataFrame, Series, Index, MultiIndex, |
| 13 | +from pandas import (compat, DataFrame, Series, Index, MultiIndex, Categorical, |
14 | 14 | date_range, isna)
|
15 | 15 | import pandas as pd
|
16 | 16 |
|
@@ -1129,6 +1129,19 @@ def test_reindex_multi(self):
|
1129 | 1129 |
|
1130 | 1130 | assert_frame_equal(result, expected)
|
1131 | 1131 |
|
| 1132 | + def test_reindex_multi_categorical_time(self): |
| 1133 | + # https://github.com/pandas-dev/pandas/issues/21390 |
| 1134 | + midx = pd.MultiIndex.from_product( |
| 1135 | + [Categorical(['a', 'b', 'c']), |
| 1136 | + Categorical(date_range("2012-01-01", periods=3, freq='H'))]) |
| 1137 | + df = pd.DataFrame({'a': range(len(midx))}, index=midx) |
| 1138 | + df2 = df.iloc[[0, 1, 2, 3, 4, 5, 6, 8]] |
| 1139 | + |
| 1140 | + result = df2.reindex(midx) |
| 1141 | + expected = pd.DataFrame( |
| 1142 | + {'a': [0, 1, 2, 3, 4, 5, 6, np.nan, 8]}, index=midx) |
| 1143 | + assert_frame_equal(result, expected) |
| 1144 | + |
1132 | 1145 | data = [[1, 2, 3], [1, 2, 3]]
|
1133 | 1146 |
|
1134 | 1147 | @pytest.mark.parametrize('actual', [
|
|
0 commit comments