@@ -323,32 +323,35 @@ def test_dti_cmp_null_scalar_inequality(self, tz_naive_fixture, other):
323
323
with pytest .raises (TypeError ):
324
324
dti >= other
325
325
326
- def test_dti_cmp_nat (self ):
326
+ @pytest .mark .parametrize ('dtype' , [None , object ])
327
+ def test_dti_cmp_nat (self , dtype ):
327
328
left = pd .DatetimeIndex ([pd .Timestamp ('2011-01-01' ), pd .NaT ,
328
329
pd .Timestamp ('2011-01-03' )])
329
330
right = pd .DatetimeIndex ([pd .NaT , pd .NaT , pd .Timestamp ('2011-01-03' )])
330
331
331
- for lhs , rhs in [(left , right ),
332
- (left .astype (object ), right .astype (object ))]:
333
- result = rhs == lhs
334
- expected = np .array ([False , False , True ])
335
- tm .assert_numpy_array_equal (result , expected )
332
+ lhs , rhs = left , right
333
+ if dtype is object :
334
+ lhs , rhs = left .astype (object ), right .astype (object )
335
+
336
+ result = rhs == lhs
337
+ expected = np .array ([False , False , True ])
338
+ tm .assert_numpy_array_equal (result , expected )
336
339
337
- result = lhs != rhs
338
- expected = np .array ([True , True , False ])
339
- tm .assert_numpy_array_equal (result , expected )
340
+ result = lhs != rhs
341
+ expected = np .array ([True , True , False ])
342
+ tm .assert_numpy_array_equal (result , expected )
340
343
341
- expected = np .array ([False , False , False ])
342
- tm .assert_numpy_array_equal (lhs == pd .NaT , expected )
343
- tm .assert_numpy_array_equal (pd .NaT == rhs , expected )
344
+ expected = np .array ([False , False , False ])
345
+ tm .assert_numpy_array_equal (lhs == pd .NaT , expected )
346
+ tm .assert_numpy_array_equal (pd .NaT == rhs , expected )
344
347
345
- expected = np .array ([True , True , True ])
346
- tm .assert_numpy_array_equal (lhs != pd .NaT , expected )
347
- tm .assert_numpy_array_equal (pd .NaT != lhs , expected )
348
+ expected = np .array ([True , True , True ])
349
+ tm .assert_numpy_array_equal (lhs != pd .NaT , expected )
350
+ tm .assert_numpy_array_equal (pd .NaT != lhs , expected )
348
351
349
- expected = np .array ([False , False , False ])
350
- tm .assert_numpy_array_equal (lhs < pd .NaT , expected )
351
- tm .assert_numpy_array_equal (pd .NaT > lhs , expected )
352
+ expected = np .array ([False , False , False ])
353
+ tm .assert_numpy_array_equal (lhs < pd .NaT , expected )
354
+ tm .assert_numpy_array_equal (pd .NaT > lhs , expected )
352
355
353
356
def test_dti_cmp_nat_behaves_like_float_cmp_nan (self ):
354
357
fidx1 = pd .Index ([1.0 , np .nan , 3.0 , np .nan , 5.0 , 7.0 ])
@@ -901,13 +904,15 @@ def test_dt64_series_add_intlike(self, tz, op):
901
904
902
905
other = Series ([20 , 30 , 40 ], dtype = 'uint8' )
903
906
904
- pytest .raises (TypeError , getattr (ser , op ), 1 )
905
-
906
- pytest .raises (TypeError , getattr (ser , op ), other )
907
-
908
- pytest .raises (TypeError , getattr (ser , op ), other .values )
909
-
910
- pytest .raises (TypeError , getattr (ser , op ), pd .Index (other ))
907
+ method = getattr (ser , op )
908
+ with pytest .raises (TypeError ):
909
+ method (1 )
910
+ with pytest .raises (TypeError ):
911
+ method (other )
912
+ with pytest .raises (TypeError ):
913
+ method (other .values )
914
+ with pytest .raises (TypeError ):
915
+ method (pd .Index (other ))
911
916
912
917
# -------------------------------------------------------------
913
918
# Timezone-Centric Tests
@@ -994,10 +999,6 @@ def test_dti_add_timestamp_raises(self, box):
994
999
msg = "cannot add"
995
1000
with tm .assert_raises_regex (TypeError , msg ):
996
1001
idx + Timestamp ('2011-01-01' )
997
-
998
- def test_dti_radd_timestamp_raises (self ):
999
- idx = DatetimeIndex (['2011-01-01' , '2011-01-02' ])
1000
- msg = "cannot add DatetimeIndex and Timestamp"
1001
1002
with tm .assert_raises_regex (TypeError , msg ):
1002
1003
Timestamp ('2011-01-01' ) + idx
1003
1004
0 commit comments