Skip to content

Commit e95175c

Browse files
Wang Haoxiangpre-commit-ci[bot]
andauthored
TST: Add regression tests for enlarging MultiIndex with None keys (GH… (#63025)
Co-authored-by: wdyy20041223 <2795352227@qq,com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2498bd1 commit e95175c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/indexing/multiindex/test_setitem.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,24 @@ def test_setitem_enlargement_keep_index_names(self):
490490
)
491491
tm.assert_frame_equal(df, expected)
492492

493+
def test_setitem_enlargement_multiindex_with_none(self):
494+
# GH#59153
495+
# enlarging a DataFrame with a MultiIndex containing None values
496+
index = MultiIndex.from_tuples(
497+
[("A", "a1"), ("A", "a2"), ("B", "b1"), ("B", None)]
498+
)
499+
df = DataFrame([(0.0, 6.0), (1.0, 5.0), (2.0, 4.0), (3.0, 7.0)], index=index)
500+
df.loc[("A", None), :] = [12.0, 13.0]
501+
expected_index = MultiIndex.from_tuples(
502+
[("A", "a1"), ("A", "a2"), ("B", "b1"), ("B", None), ("A", None)]
503+
)
504+
expected = DataFrame(
505+
[[0.0, 6.0], [1.0, 5.0], [2.0, 4.0], [3.0, 7.0], [12.0, 13.0]],
506+
index=expected_index,
507+
columns=[0, 1],
508+
)
509+
tm.assert_frame_equal(df, expected, check_index_type=False)
510+
493511

494512
def test_frame_setitem_view_direct(multiindex_dataframe_random_data):
495513
# this works because we are modifying the underlying array

0 commit comments

Comments
 (0)