Skip to content

Commit d660810

Browse files
authored
TST: Adds CategoricalIndex DataFrame from_records test (GH32805) (#35055)
* TST: Adds CategoricalIndex DataFrame from_records test (GH32805) * TST: Reformats CategoricalIndex DataFrame from_records test * TST: Removes comma from CategoricalIndex DataFrame from_records test * TST: Isorts tests/frame/test_constructor.py imports
1 parent 05a41bc commit d660810

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/frame/test_constructors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pandas as pd
2020
from pandas import (
2121
Categorical,
22+
CategoricalIndex,
2223
DataFrame,
2324
Index,
2425
Interval,
@@ -2509,6 +2510,18 @@ def test_from_records_series_list_dict(self):
25092510
result = DataFrame.from_records(data)
25102511
tm.assert_frame_equal(result, expected)
25112512

2513+
def test_from_records_series_categorical_index(self):
2514+
# GH 32805
2515+
index = CategoricalIndex(
2516+
[pd.Interval(-20, -10), pd.Interval(-10, 0), pd.Interval(0, 10)]
2517+
)
2518+
series_of_dicts = pd.Series([{"a": 1}, {"a": 2}, {"b": 3}], index=index)
2519+
frame = pd.DataFrame.from_records(series_of_dicts, index=index)
2520+
expected = DataFrame(
2521+
{"a": [1, 2, np.NaN], "b": [np.NaN, np.NaN, 3]}, index=index
2522+
)
2523+
tm.assert_frame_equal(frame, expected)
2524+
25122525
def test_frame_from_records_utc(self):
25132526
rec = {"datum": 1.5, "begin_time": datetime(2006, 4, 27, tzinfo=pytz.utc)}
25142527

0 commit comments

Comments
 (0)