Skip to content

Commit ee87789

Browse files
committed
BUG: Move new test to test_multilevel.py
1 parent 19bbdb9 commit ee87789

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

pandas/tests/frame/methods/test_reset_index.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -544,27 +544,6 @@ def test_reset_index_datetime3(self, tz_naive_fixture):
544544
result = df.reset_index()
545545
tm.assert_frame_equal(result, expected)
546546

547-
def test_reset_index_multiindex_dt_with_nan(self):
548-
# GH#60388
549-
df = DataFrame(
550-
{
551-
"Date": [
552-
datetime(2024, 11, 1),
553-
datetime(2024, 11, 1),
554-
datetime(2024, 11, 2),
555-
datetime(2024, 11, 2),
556-
],
557-
"sub": ["a", "b", "c", "d"],
558-
"value1": [1, 2, 3, 4],
559-
"value2": [5, 6, 7, 8],
560-
}
561-
)
562-
df = df.pivot(index="sub", columns="Date", values=["value1", "value2"])
563-
df = df.reset_index()
564-
result = df[df.columns[0]]
565-
expected = Series(["a", "b", "c", "d"], name=("sub", np.nan))
566-
tm.assert_series_equal(result, expected)
567-
568547
def test_reset_index_period(self):
569548
# GH#7746
570549
idx = MultiIndex.from_product(

pandas/tests/test_multilevel.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,29 @@ def test_multiindex_insert_level_with_na(self, na):
295295
df[na, "B"] = 1
296296
tm.assert_frame_equal(df[na], DataFrame([1], columns=["B"]))
297297

298+
def test_multiindex_dt_with_nan(self):
299+
# GH#60388
300+
df = DataFrame(
301+
[
302+
[1, np.nan, 5, np.nan],
303+
[2, np.nan, 6, np.nan],
304+
[np.nan, 3, np.nan, 7],
305+
[np.nan, 4, np.nan, 8],
306+
],
307+
index=Series(["a", "b", "c", "d"], dtype=object, name="sub"),
308+
columns=MultiIndex.from_product(
309+
[
310+
["value1", "value2"],
311+
[datetime.datetime(2024, 11, 1), datetime.datetime(2024, 11, 2)],
312+
],
313+
names=[None, "Date"],
314+
),
315+
)
316+
df = df.reset_index()
317+
result = df[df.columns[0]]
318+
expected = Series(["a", "b", "c", "d"], name=("sub", np.nan))
319+
tm.assert_series_equal(result, expected)
320+
298321

299322
class TestSorted:
300323
"""everything you wanted to test about sorting"""

0 commit comments

Comments
 (0)