Skip to content

Commit 7f285d4

Browse files
committed
TST: add regression test for GH#56853 (insert/delete with MultiIndex datetime)
1 parent 7bfef3b commit 7f285d4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pandas/tests/frame/indexing/test_insert.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pandas import (
1111
DataFrame,
1212
Index,
13+
MultiIndex,
1314
)
1415
import pandas._testing as tm
1516

@@ -94,3 +95,27 @@ def test_insert_int64_loc(self):
9495
df = DataFrame({"a": [1, 2]})
9596
df.insert(np.int64(0), "b", 0)
9697
tm.assert_frame_equal(df, DataFrame({"b": [0, 0], "a": [1, 2]}))
98+
99+
def test_insert_delete_mixed_multiindex_columns(self):
100+
# GH#56853
101+
from pandas import (
102+
DataFrame,
103+
Timestamp,
104+
)
105+
106+
df = DataFrame({("A", Timestamp("2024-01-01")): [0]})
107+
108+
# Insert scalar label 'B'; alongside MultiIndex columns
109+
df.insert(1, "B", [1])
110+
111+
# Verify MultiIndex and that 'B' appears in the top level
112+
assert isinstance(df.columns, MultiIndex)
113+
assert "B" in df.columns.get_level_values(0)
114+
115+
# Should not raise RecursionError (this was the original bug)
116+
del df["B"]
117+
118+
# Confirm 'B' no longer present and structure restored
119+
assert "B" not in df.columns.get_level_values(0)
120+
expected = DataFrame({("A", Timestamp("2024-01-01")): [0]})
121+
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)