MCPcopy
hub / github.com/pandas-dev/pandas / test_multi_index_rows

Function test_multi_index_rows

pandas/tests/frame/methods/test_explode.py:77–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75
76
77def test_multi_index_rows():
78 df = pd.DataFrame(
79 {"A": np.array([[0, 1, 2], np.nan, [], (3, 4)], dtype=object), "B": 1},
80 index=pd.MultiIndex.from_tuples([("a", 1), ("a", 2), ("b", 1), ("b", 2)]),
81 )
82
83 result = df.explode("A")
84 expected = pd.DataFrame(
85 {
86 "A": pd.Series(
87 [0, 1, 2, np.nan, np.nan, 3, 4],
88 index=pd.MultiIndex.from_tuples(
89 [
90 ("a", 1),
91 ("a", 1),
92 ("a", 1),
93 ("a", 2),
94 ("b", 1),
95 ("b", 2),
96 ("b", 2),
97 ]
98 ),
99 dtype=object,
100 ),
101 "B": 1,
102 }
103 )
104 tm.assert_frame_equal(result, expected)
105
106
107def test_multi_index_columns():

Callers

nothing calls this directly

Calls 3

explodeMethod · 0.95
arrayMethod · 0.45
from_tuplesMethod · 0.45

Tested by

no test coverage detected