1616
1717def test_index_relops () -> None :
1818 # GH 265
19- data = pd .date_range ("2022-01-01" , "2022-01-31" , freq = "D" )
19+ data = check (
20+ assert_type (
21+ pd .date_range ("2022-01-01" , "2022-01-31" , freq = "D" ), pd .DatetimeIndex
22+ ),
23+ pd .DatetimeIndex ,
24+ )
2025 x = pd .Timestamp ("2022-01-17" )
21- idx = pd .Index (data , name = "date" )
26+ idx = check (
27+ assert_type (pd .Index (data , name = "date" ), "pd.Index[pd.Timestamp]" ), pd .Index
28+ )
2229 check (assert_type (data [x <= idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
2330 check (assert_type (data [x < idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
2431 check (assert_type (data [x >= idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
2532 check (assert_type (data [x > idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
33+ check (assert_type (data [idx <= x ], pd .DatetimeIndex ), pd .DatetimeIndex )
2634 check (assert_type (data [idx < x ], pd .DatetimeIndex ), pd .DatetimeIndex )
2735 check (assert_type (data [idx >= x ], pd .DatetimeIndex ), pd .DatetimeIndex )
2836 check (assert_type (data [idx > x ], pd .DatetimeIndex ), pd .DatetimeIndex )
29- check (assert_type (data [idx <= x ], pd .DatetimeIndex ), pd .DatetimeIndex )
3037
3138 dt_idx = pd .DatetimeIndex (data , name = "date" )
3239 check (assert_type (data [x <= dt_idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
33- check (assert_type (data [x >= dt_idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
3440 check (assert_type (data [x < dt_idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
41+ check (assert_type (data [x >= dt_idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
3542 check (assert_type (data [x > dt_idx ], pd .DatetimeIndex ), pd .DatetimeIndex )
3643 check (assert_type (data [dt_idx <= x ], pd .DatetimeIndex ), pd .DatetimeIndex )
37- check (assert_type (data [dt_idx >= x ], pd .DatetimeIndex ), pd .DatetimeIndex )
3844 check (assert_type (data [dt_idx < x ], pd .DatetimeIndex ), pd .DatetimeIndex )
45+ check (assert_type (data [dt_idx >= x ], pd .DatetimeIndex ), pd .DatetimeIndex )
3946 check (assert_type (data [dt_idx > x ], pd .DatetimeIndex ), pd .DatetimeIndex )
4047
4148 ind = pd .Index ([1 , 2 , 3 ])
4249 check (assert_type (ind <= 2 , np_1darray [np .bool ]), np_1darray [np .bool ])
43- check (assert_type (ind >= 2 , np_1darray [np .bool ]), np_1darray [np .bool ])
4450 check (assert_type (ind < 2 , np_1darray [np .bool ]), np_1darray [np .bool ])
51+ check (assert_type (ind >= 2 , np_1darray [np .bool ]), np_1darray [np .bool ])
4552 check (assert_type (ind > 2 , np_1darray [np .bool ]), np_1darray [np .bool ])
4653
4754
@@ -97,8 +104,14 @@ def test_datetimeindex_shift() -> None:
97104
98105def test_datetimeindex_indexer_at_time () -> None :
99106 dti = pd .date_range ("2023-01-01" , "2023-02-01" )
100- check (assert_type (dti .indexer_at_time ("10:00" ), np_1darray [np .intp ]), np_1darray )
101- check (assert_type (dti .indexer_at_time (time (10 )), np_1darray [np .intp ]), np_1darray )
107+ check (
108+ assert_type (dti .indexer_at_time ("10:00" ), np_1darray [np .intp ]),
109+ np_1darray [np .intp ],
110+ )
111+ check (
112+ assert_type (dti .indexer_at_time (time (10 )), np_1darray [np .intp ]),
113+ np_1darray [np .intp ],
114+ )
102115
103116
104117def test_datetimeindex_indexer_between_time () -> None :
@@ -110,9 +123,20 @@ def test_datetimeindex_indexer_between_time() -> None:
110123 ),
111124 np_1darray [np .intp ],
112125 ),
113- np_1darray ,
126+ np_1darray [ np . intp ] ,
114127 )
115128 check (
116129 assert_type (dti .indexer_between_time (time (10 ), "11:00" ), np_1darray [np .intp ]),
117- np_1darray ,
130+ np_1darray [np .intp ],
131+ )
132+
133+
134+ def test_datetimeindex_snap () -> None :
135+ dti = pd .date_range ("2023-01-01" , "2023-02-01" )
136+ check (
137+ assert_type (
138+ dti .snap ("MS" ),
139+ pd .DatetimeIndex ,
140+ ),
141+ pd .DatetimeIndex ,
118142 )
0 commit comments