zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pandas import (
    Index,
    NaT,
    Period,
    PeriodIndex,
)
import pandas._testing as tm
 
 
class TestFillNA:
    def test_fillna_period(self):
        # GH#11343
        idx = PeriodIndex(["2011-01-01 09:00", NaT, "2011-01-01 11:00"], freq="H")
 
        exp = PeriodIndex(
            ["2011-01-01 09:00", "2011-01-01 10:00", "2011-01-01 11:00"], freq="H"
        )
        result = idx.fillna(Period("2011-01-01 10:00", freq="H"))
        tm.assert_index_equal(result, exp)
 
        exp = Index(
            [
                Period("2011-01-01 09:00", freq="H"),
                "x",
                Period("2011-01-01 11:00", freq="H"),
            ],
            dtype=object,
        )
        result = idx.fillna("x")
        tm.assert_index_equal(result, exp)
 
        exp = Index(
            [
                Period("2011-01-01 09:00", freq="H"),
                Period("2011-01-01", freq="D"),
                Period("2011-01-01 11:00", freq="H"),
            ],
            dtype=object,
        )
        result = idx.fillna(Period("2011-01-01", freq="D"))
        tm.assert_index_equal(result, exp)