Skip to content

Commit 9ae990d

Browse files
shtekenYi Wei
authored and
Yi Wei
committed
TST: Add a test for multiindex df with na value and adding a new row (pandas-dev#53010)
* add test_multiindex_with_na * address comments in pr
1 parent c126ddd commit 9ae990d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/test_multilevel.py

+24
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,30 @@ def test_datetime_object_multiindex(self):
290290

291291
tm.assert_frame_equal(result, expected)
292292

293+
def test_multiindex_with_na(self):
294+
df = DataFrame(
295+
[
296+
["A", np.nan, 1.23, 4.56],
297+
["A", "G", 1.23, 4.56],
298+
["A", "D", 9.87, 10.54],
299+
],
300+
columns=["pivot_0", "pivot_1", "col_1", "col_2"],
301+
).set_index(["pivot_0", "pivot_1"])
302+
303+
df.at[("A", "F"), "col_2"] = 0.0
304+
305+
expected = DataFrame(
306+
[
307+
["A", np.nan, 1.23, 4.56],
308+
["A", "G", 1.23, 4.56],
309+
["A", "D", 9.87, 10.54],
310+
["A", "F", np.nan, 0.0],
311+
],
312+
columns=["pivot_0", "pivot_1", "col_1", "col_2"],
313+
).set_index(["pivot_0", "pivot_1"])
314+
315+
tm.assert_frame_equal(df, expected)
316+
293317

294318
class TestSorted:
295319
"""everything you wanted to test about sorting"""

0 commit comments

Comments
 (0)