Skip to content

Commit 37377e4

Browse files
louishuynhMateusz Górski
authored and
Mateusz Górski
committed
TST: Add test to check category dtype remains unchanged after concat. (pandas-dev#29352)
1 parent 760b8fe commit 37377e4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/reshape/test_concat.py

+16
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,22 @@ def test_concat_categorical_tz():
27472747
tm.assert_series_equal(result, expected)
27482748

27492749

2750+
def test_concat_categorical_unchanged():
2751+
# GH-12007
2752+
# test fix for when concat on categorical and float
2753+
# coerces dtype categorical -> float
2754+
df = pd.DataFrame(pd.Series(["a", "b", "c"], dtype="category", name="A"))
2755+
ser = pd.Series([0, 1, 2], index=[0, 1, 3], name="B")
2756+
result = pd.concat([df, ser], axis=1)
2757+
expected = pd.DataFrame(
2758+
{
2759+
"A": pd.Series(["a", "b", "c", np.nan], dtype="category"),
2760+
"B": pd.Series([0, 1, np.nan, 2], dtype="float"),
2761+
}
2762+
)
2763+
tm.assert_equal(result, expected)
2764+
2765+
27502766
def test_concat_datetimeindex_freq():
27512767
# GH 3232
27522768
# Monotonic index result

0 commit comments

Comments
 (0)