Skip to content
Merged
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
37 changes: 37 additions & 0 deletions pandas/tests/indexes/multi/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest

import pandas as pd
from pandas import MultiIndex
import pandas._testing as tm

Expand Down Expand Up @@ -83,3 +84,39 @@ def test_inplace_mutation_resets_values():

# Should have correct values
tm.assert_almost_equal(exp_values, new_values)


def test_boxable_categorical_values():
cat = pd.Categorical(pd.date_range("2012-01-01", periods=3, freq="H"))
result = MultiIndex.from_product([["a", "b", "c"], cat]).values
expected = pd.Series(
[
("a", pd.Timestamp("2012-01-01 00:00:00")),
("a", pd.Timestamp("2012-01-01 01:00:00")),
("a", pd.Timestamp("2012-01-01 02:00:00")),
("b", pd.Timestamp("2012-01-01 00:00:00")),
("b", pd.Timestamp("2012-01-01 01:00:00")),
("b", pd.Timestamp("2012-01-01 02:00:00")),
("c", pd.Timestamp("2012-01-01 00:00:00")),
("c", pd.Timestamp("2012-01-01 01:00:00")),
("c", pd.Timestamp("2012-01-01 02:00:00")),
]
).values
tm.assert_numpy_array_equal(result, expected)
result = pd.DataFrame({"a": ["a", "b", "c"], "b": cat, "c": np.array(cat)}).values
expected = pd.DataFrame(
{
"a": ["a", "b", "c"],
"b": [
pd.Timestamp("2012-01-01 00:00:00"),
pd.Timestamp("2012-01-01 01:00:00"),
pd.Timestamp("2012-01-01 02:00:00"),
],
"c": [
pd.Timestamp("2012-01-01 00:00:00"),
pd.Timestamp("2012-01-01 01:00:00"),
pd.Timestamp("2012-01-01 02:00:00"),
],
}
).values
tm.assert_numpy_array_equal(result, expected)