Skip to content

Commit a66a60f

Browse files
author
tyuyoshi
committed
TST: pd.concat frames with categorical indices
1 parent b8f5c0e commit a66a60f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/reshape/concat/test_concat.py

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pandas import (
2121
DataFrame,
2222
Index,
23+
CategoricalIndex,
2324
MultiIndex,
2425
PeriodIndex,
2526
Series,
@@ -502,6 +503,23 @@ def test_concat_duplicate_indices_raise(self):
502503
with pytest.raises(InvalidIndexError, match=msg):
503504
concat([df1, df2], axis=1)
504505

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)
505523

506524
@pytest.mark.parametrize("pdt", [Series, DataFrame])
507525
@pytest.mark.parametrize("dt", np.sctypes["float"])

0 commit comments

Comments
 (0)