Skip to content

Commit 2b9898b

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

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pandas/tests/indexes/multi/test_compat.py

+37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
import pandas as pd
45
from pandas import MultiIndex
56
import pandas._testing as tm
67

@@ -83,3 +84,39 @@ def test_inplace_mutation_resets_values():
8384

8485
# Should have correct values
8586
tm.assert_almost_equal(exp_values, new_values)
87+
88+
89+
def test_boxable_categorical_values():
90+
cat = pd.Categorical(pd.date_range("2012-01-01", periods=3, freq="H"))
91+
result = MultiIndex.from_product([["a", "b", "c"], cat]).values
92+
expected = pd.Series(
93+
[
94+
("a", pd.Timestamp("2012-01-01 00:00:00")),
95+
("a", pd.Timestamp("2012-01-01 01:00:00")),
96+
("a", pd.Timestamp("2012-01-01 02:00:00")),
97+
("b", pd.Timestamp("2012-01-01 00:00:00")),
98+
("b", pd.Timestamp("2012-01-01 01:00:00")),
99+
("b", pd.Timestamp("2012-01-01 02:00:00")),
100+
("c", pd.Timestamp("2012-01-01 00:00:00")),
101+
("c", pd.Timestamp("2012-01-01 01:00:00")),
102+
("c", pd.Timestamp("2012-01-01 02:00:00")),
103+
]
104+
).values
105+
tm.assert_numpy_array_equal(result, expected)
106+
result = pd.DataFrame({"a": ["a", "b", "c"], "b": cat, "c": np.array(cat)}).values
107+
expected = pd.DataFrame(
108+
{
109+
"a": ["a", "b", "c"],
110+
"b": [
111+
pd.Timestamp("2012-01-01 00:00:00"),
112+
pd.Timestamp("2012-01-01 01:00:00"),
113+
pd.Timestamp("2012-01-01 02:00:00"),
114+
],
115+
"c": [
116+
pd.Timestamp("2012-01-01 00:00:00"),
117+
pd.Timestamp("2012-01-01 01:00:00"),
118+
pd.Timestamp("2012-01-01 02:00:00"),
119+
],
120+
}
121+
).values
122+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)