@@ -2179,6 +2179,93 @@ def test_comparisons_coverage(self):
2179
2179
exp = rng == rng
2180
2180
self .assert_numpy_array_equal (result , exp )
2181
2181
2182
+ def test_comparisons_nat (self ):
2183
+ fidx1 = pd .Index ([1.0 , np .nan , 3.0 , np .nan , 5.0 , 7.0 ])
2184
+ fidx2 = pd .Index ([2.0 , 3.0 , np .nan , np .nan , 6.0 , 7.0 ])
2185
+
2186
+ didx1 = pd .DatetimeIndex (['2014-01-01' , pd .NaT , '2014-03-01' , pd .NaT ,
2187
+ '2014-05-01' , '2014-07-01' ])
2188
+ didx2 = pd .DatetimeIndex (['2014-02-01' , '2014-03-01' , pd .NaT , pd .NaT ,
2189
+ '2014-06-01' , '2014-07-01' ])
2190
+ darr = np .array ([np .datetime64 ('2014-02-01 00:00Z' ),
2191
+ np .datetime64 ('2014-03-01 00:00Z' ),
2192
+ np .datetime64 ('nat' ), np .datetime64 ('nat' ),
2193
+ np .datetime64 ('2014-06-01 00:00Z' ),
2194
+ np .datetime64 ('2014-07-01 00:00Z' )])
2195
+
2196
+ if _np_version_under1p7 :
2197
+ # cannot test array because np.datetime('nat') returns today's date
2198
+ cases = [(fidx1 , fidx2 ), (didx1 , didx2 )]
2199
+ else :
2200
+ cases = [(fidx1 , fidx2 ), (didx1 , didx2 ), (didx1 , darr )]
2201
+
2202
+ # Check pd.NaT is handles as the same as np.nan
2203
+ for idx1 , idx2 in cases :
2204
+ result = idx1 < idx2
2205
+ expected = np .array ([True , False , False , False , True , False ])
2206
+ self .assert_numpy_array_equal (result , expected )
2207
+ result = idx2 > idx1
2208
+ expected = np .array ([True , False , False , False , True , False ])
2209
+ self .assert_numpy_array_equal (result , expected )
2210
+
2211
+ result = idx1 <= idx2
2212
+ expected = np .array ([True , False , False , False , True , True ])
2213
+ self .assert_numpy_array_equal (result , expected )
2214
+ result = idx2 >= idx1
2215
+ expected = np .array ([True , False , False , False , True , True ])
2216
+ self .assert_numpy_array_equal (result , expected )
2217
+
2218
+ result = idx1 == idx2
2219
+ expected = np .array ([False , False , False , False , False , True ])
2220
+ self .assert_numpy_array_equal (result , expected )
2221
+
2222
+ result = idx1 != idx2
2223
+ expected = np .array ([True , True , True , True , True , False ])
2224
+ self .assert_numpy_array_equal (result , expected )
2225
+
2226
+ for idx1 , val in [(fidx1 , np .nan ), (didx1 , pd .NaT )]:
2227
+ result = idx1 < val
2228
+ expected = np .array ([False , False , False , False , False , False ])
2229
+ self .assert_numpy_array_equal (result , expected )
2230
+ result = idx1 > val
2231
+ self .assert_numpy_array_equal (result , expected )
2232
+
2233
+ result = idx1 <= val
2234
+ self .assert_numpy_array_equal (result , expected )
2235
+ result = idx1 >= val
2236
+ self .assert_numpy_array_equal (result , expected )
2237
+
2238
+ result = idx1 == val
2239
+ self .assert_numpy_array_equal (result , expected )
2240
+
2241
+ result = idx1 != val
2242
+ expected = np .array ([True , True , True , True , True , True ])
2243
+ self .assert_numpy_array_equal (result , expected )
2244
+
2245
+ # Check pd.NaT is handles as the same as np.nan
2246
+ for idx1 , val in [(fidx1 , 3 ), (didx1 , datetime (2014 , 3 , 1 ))]:
2247
+ result = idx1 < val
2248
+ expected = np .array ([True , False , False , False , False , False ])
2249
+ self .assert_numpy_array_equal (result , expected )
2250
+ result = idx1 > val
2251
+ expected = np .array ([False , False , False , False , True , True ])
2252
+ self .assert_numpy_array_equal (result , expected )
2253
+
2254
+ result = idx1 <= val
2255
+ expected = np .array ([True , False , True , False , False , False ])
2256
+ self .assert_numpy_array_equal (result , expected )
2257
+ result = idx1 >= val
2258
+ expected = np .array ([False , False , True , False , True , True ])
2259
+ self .assert_numpy_array_equal (result , expected )
2260
+
2261
+ result = idx1 == val
2262
+ expected = np .array ([False , False , True , False , False , False ])
2263
+ self .assert_numpy_array_equal (result , expected )
2264
+
2265
+ result = idx1 != val
2266
+ expected = np .array ([True , True , False , True , True , True ])
2267
+ self .assert_numpy_array_equal (result , expected )
2268
+
2182
2269
def test_map (self ):
2183
2270
rng = date_range ('1/1/2000' , periods = 10 )
2184
2271
0 commit comments