diff --git a/pandas/tests/reshape/concat/test_categorical.py b/pandas/tests/reshape/concat/test_categorical.py index 5bafd2e8e8503..c2030828d1cac 100644 --- a/pandas/tests/reshape/concat/test_categorical.py +++ b/pandas/tests/reshape/concat/test_categorical.py @@ -1,3 +1,5 @@ +from datetime import datetime + import numpy as np from pandas.core.dtypes.dtypes import CategoricalDtype @@ -203,6 +205,32 @@ def test_categorical_concat_gh7864(self): dfa = df1._append(df2) tm.assert_index_equal(df["grade"].cat.categories, dfa["grade"].cat.categories) + def test_categorical_datetime_concat(self): + # GH 39443 + # test catergorical dataframes both containing datetimes + df1 = DataFrame( + {"x": Series(datetime(2021, 1, 1), index=[0], dtype="category")} + ) + df2 = DataFrame( + {"x": Series(datetime(2021, 1, 2), index=[1], dtype="category")} + ) + expected = DataFrame( + {"x": Series([datetime(2021, 1, 1), datetime(2021, 1, 2)])} + ) + result = pd.concat([df1, df2]) + tm.assert_equal(result, expected) + + def test_categorical_datetime_and_string_concat(self): + # GH 39443 + # test catergorical dataframes one with datetime, one with a string + df1 = DataFrame( + {"x": Series(datetime(2021, 1, 1), index=[0], dtype="category")} + ) + df2 = DataFrame({"x": Series("test string", index=[1], dtype="category")}) + expected = DataFrame({"x": Series([datetime(2021, 1, 1), "test string"])}) + result = pd.concat([df1, df2]) + tm.assert_equal(result, expected) + def test_categorical_index_upcast(self): # GH 17629 # test upcasting to object when concatinating on categorical indexes