Repository: pandas-dev/pandas
File: pandas/tests/frame/test_constructors.py (Python)

Code before:
            [
                [0, None, None, None],
                [None, 2, None, None],
                [None, None, 4, None],
                [None, None, None, 6],
            ],
            index=[Timestamp(dt) for dt in dates_as_str],
        )

        result_datetime64 = DataFrame(data_datetime64)
        assert result_datetime64.index.unit == "s"
        result_datetime64.index = result_datetime64.index.as_unit("us")
        result_datetime = DataFrame(data_datetime)
        assert result_datetime.index.unit == "us"
        result_Timestamp = DataFrame(data_Timestamp)
        tm.assert_frame_equal(result_datetime64, expected)
        tm.assert_frame_equal(result_datetime, expected)
        tm.assert_frame_equal(result_Timestamp, expected)

    @pytest.mark.parametrize(
        "klass,exp_dtype",
        [
            (lambda x: np.timedelta64(x, "D"), "m8[s]"),
            (lambda x: timedelta(days=x), "m8[us]"),
            (lambda x: Timedelta(x, "D"), "m8[s]"),
            (lambda x: Timedelta(x, "D").as_unit("s"), "m8[s]"),
        ],
    )
    def test_constructor_dict_timedelta64_index(self, klass, exp_dtype):
        # GH 10160
        td_as_int = [1, 2, 3, 4]

        data = {i: {klass(s): 2 * i} for i, s in enumerate(td_as_int)}

        expected = DataFrame(
            [
                {0: 0, 1: None, 2: None, 3: None},
                {0: None, 1: 2, 2: None, 3: None},
                {0: None, 1: None, 2: 4, 3: None},
                {0: None, 1: None, 2: None, 3: 6},
            ],
            index=[Timedelta(td, "D") for td in td_as_int],
        )
        expected.index = expected.index.astype(exp_dtype)

        result = DataFrame(data)

        tm.assert_frame_equal(result, expected)

    def test_constructor_period_dict(self):
        # PeriodIndex

Review comment (suggestion):
```suggestion
            (lambda x: Timedelta(x, "D").as_unit("ms"), "m8[ms]"),
```

Otherwise it is the same as the case above now. Or just remove the case alltogether

Code after:
            [
                [0, None, None, None],
                [None, 2, None, None],
                [None, None, 4, None],
                [None, None, None, 6],
            ],
            index=[Timestamp(dt) for dt in dates_as_str],
        )

        result_datetime64 = DataFrame(data_datetime64)
        assert result_datetime64.index.unit == "s"
        result_datetime64.index = result_datetime64.index.as_unit("us")
        result_datetime = DataFrame(data_datetime)
        assert result_datetime.index.unit == "us"
        result_Timestamp = DataFrame(data_Timestamp)
        tm.assert_frame_equal(result_datetime64, expected)
        tm.assert_frame_equal(result_datetime, expected)
        tm.assert_frame_equal(result_Timestamp, expected)

    @pytest.mark.parametrize(
        "klass,exp_dtype",
        [
            (lambda x: np.timedelta64(x, "D"), "m8[s]"),
            (lambda x: timedelta(days=x), "m8[us]"),
            (lambda x: Timedelta(x, "D"), "m8[s]"),
            (lambda x: Timedelta(x, "D").as_unit("ms"), "m8[ms]"),
        ],
    )
    def test_constructor_dict_timedelta64_index(self, klass, exp_dtype):
        # GH 10160
        td_as_int = [1, 2, 3, 4]

        data = {i: {klass(s): 2 * i} for i, s in enumerate(td_as_int)}

        expected = DataFrame(
            [
                {0: 0, 1: None, 2: None, 3: None},
                {0: None, 1: 2, 2: None, 3: None},
                {0: None, 1: None, 2: 4, 3: None},
                {0: None, 1: None, 2: None, 3: 6},
            ],
            index=[Timedelta(td, "D") for td in td_as_int],
        )
        expected.index = expected.index.astype(exp_dtype)

        result = DataFrame(data)

        tm.assert_frame_equal(result, expected)

    def test_constructor_period_dict(self):
        # PeriodIndex