|
20 | 20 | from pandas import (
|
21 | 21 | DataFrame,
|
22 | 22 | Index,
|
| 23 | + CategoricalIndex, |
23 | 24 | MultiIndex,
|
24 | 25 | PeriodIndex,
|
25 | 26 | Series,
|
@@ -502,6 +503,23 @@ def test_concat_duplicate_indices_raise(self):
|
502 | 503 | with pytest.raises(InvalidIndexError, match=msg):
|
503 | 504 | concat([df1, df2], axis=1)
|
504 | 505 |
|
| 506 | + def test_concat_with_categorical_indices(self): |
| 507 | + # GH 44099 |
| 508 | + # concat frames with categorical indices that have the same values |
| 509 | + |
| 510 | + df1 = DataFrame( |
| 511 | + {"col1": ["a_val", "b_val", "c_val"]}, |
| 512 | + index=CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"]), |
| 513 | + ) |
| 514 | + df2 = DataFrame( |
| 515 | + {"col1": ["b_val", "a_val", "c_val"]}, |
| 516 | + index=CategoricalIndex(["b", "a", "c"], categories=["b", "a", "c"]), |
| 517 | + ) |
| 518 | + expected = DataFrame( |
| 519 | + {"col1": ["a_val", "b_val", "c_val", "b_val", "a_val", "c_val"]}, |
| 520 | + index=CategoricalIndex(["a", "b", "c", "b", "a", "c"], categories=["a", "b", "c"]), |
| 521 | + ) |
| 522 | + tm.assert_frame_equal(concat([df1, df2]), expected) |
505 | 523 |
|
506 | 524 | @pytest.mark.parametrize("pdt", [Series, DataFrame])
|
507 | 525 | @pytest.mark.parametrize("dt", np.sctypes["float"])
|
|
0 commit comments