Skip to content

Add test for concat with categorical + datetime dataframes #45527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pandas/tests/reshape/concat/test_categorical.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

import numpy as np

from pandas.core.dtypes.dtypes import CategoricalDtype
Expand Down Expand Up @@ -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
Expand Down