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
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
import pytest
 
from pandas import (
    DatetimeIndex,
    NaT,
    PeriodIndex,
    TimedeltaIndex,
)
import pandas._testing as tm
 
 
class NATests:
    def test_nat(self, index_without_na):
        empty_index = index_without_na[:0]
 
        index_with_na = index_without_na.copy(deep=True)
        index_with_na._data[1] = NaT
 
        assert empty_index._na_value is NaT
        assert index_with_na._na_value is NaT
        assert index_without_na._na_value is NaT
 
        idx = index_without_na
        assert idx._can_hold_na
 
        tm.assert_numpy_array_equal(idx._isnan, np.array([False, False]))
        assert idx.hasnans is False
 
        idx = index_with_na
        assert idx._can_hold_na
 
        tm.assert_numpy_array_equal(idx._isnan, np.array([False, True]))
        assert idx.hasnans is True
 
 
class TestDatetimeIndexNA(NATests):
    @pytest.fixture
    def index_without_na(self, tz_naive_fixture):
        tz = tz_naive_fixture
        return DatetimeIndex(["2011-01-01", "2011-01-02"], tz=tz)
 
 
class TestTimedeltaIndexNA(NATests):
    @pytest.fixture
    def index_without_na(self):
        return TimedeltaIndex(["1 days", "2 days"])
 
 
class TestPeriodIndexNA(NATests):
    @pytest.fixture
    def index_without_na(self):
        return PeriodIndex(["2011-01-01", "2011-01-02"], freq="D")