Skip to content

Commit 63156b3

Browse files
author
Mateusz Górski
committed
Add parametrization of name, simplify expected construction
1 parent 4fc1148 commit 63156b3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pandas/tests/indexes/datetimes/test_datetime.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,18 @@ def test_to_frame_datetime_tz(self):
458458
expected = DataFrame(idx, index=idx)
459459
tm.assert_frame_equal(result, expected)
460460

461-
def test_index_map(self):
461+
@pytest.mark.parametrize("name", [None, "name"])
462+
def test_index_map(self, name):
462463
# see GH20990
463464
count = 6
464-
index = pd.date_range("2018-01-01", periods=count, freq="M", name="name")
465+
index = pd.date_range("2018-01-01", periods=count, freq="M", name=name)
465466
a = pd.Series(np.arange(count), index=index)
466467
a.index = a.index.map(lambda x: (x.year, x.month))
467468

468-
df = pd.DataFrame([[2018, i + 1] for i in range(6)], columns=["name", "name"])
469-
exp_index = pd.MultiIndex.from_frame(df)
469+
exp_index = pd.MultiIndex.from_arrays(
470+
[[2018 for i in range(count)], [i for i in range(1, count + 1)]],
471+
names=[name, name],
472+
)
470473
expected = pd.Series(np.arange(count), index=exp_index)
471474

472475
tm.assert_series_equal(a, expected)

0 commit comments

Comments
 (0)