Skip to content

Commit 1069ab5

Browse files
committed
TST: Add test for boxable categories GH#21658
Signed-off-by: Liang Yan <[email protected]>
1 parent 4d217a4 commit 1069ab5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pandas/tests/dtypes/test_common.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,39 @@ def test_pandas_dtype_numpy_warning():
782782
match="Converting `np.integer` or `np.signedinteger` to a dtype is deprecated",
783783
):
784784
pandas_dtype(np.integer)
785+
786+
787+
def test_boxable_categorical_values():
788+
cat = pd.Categorical(pd.date_range("2012-01-01", periods=3, freq="H"))
789+
result = pd.MultiIndex.from_product([["a", "b", "c"], cat]).values
790+
expected = pd.Series(
791+
[
792+
("a", pd.Timestamp("2012-01-01 00:00:00")),
793+
("a", pd.Timestamp("2012-01-01 01:00:00")),
794+
("a", pd.Timestamp("2012-01-01 02:00:00")),
795+
("b", pd.Timestamp("2012-01-01 00:00:00")),
796+
("b", pd.Timestamp("2012-01-01 01:00:00")),
797+
("b", pd.Timestamp("2012-01-01 02:00:00")),
798+
("c", pd.Timestamp("2012-01-01 00:00:00")),
799+
("c", pd.Timestamp("2012-01-01 01:00:00")),
800+
("c", pd.Timestamp("2012-01-01 02:00:00")),
801+
]
802+
).values
803+
tm.assert_numpy_array_equal(result, expected)
804+
result = pd.DataFrame({"a": ["a", "b", "c"], "b": cat, "c": np.array(cat)}).values
805+
expected = pd.DataFrame(
806+
{
807+
"a": ["a", "b", "c"],
808+
"b": [
809+
pd.Timestamp("2012-01-01 00:00:00"),
810+
pd.Timestamp("2012-01-01 01:00:00"),
811+
pd.Timestamp("2012-01-01 02:00:00"),
812+
],
813+
"c": [
814+
pd.Timestamp("2012-01-01 00:00:00"),
815+
pd.Timestamp("2012-01-01 01:00:00"),
816+
pd.Timestamp("2012-01-01 02:00:00"),
817+
],
818+
}
819+
).values
820+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)