@@ -59,19 +59,26 @@ def test_diff(self):
59
59
60
60
@pytest .mark .parametrize ('axis' , [0 , 1 ])
61
61
@pytest .mark .parametrize ('tz' , [None , 'UTC' ])
62
- @pytest .mark .xfail (raises = NotImplementedError )
63
62
def test_diff_datetime (self , axis , tz ):
64
63
# GH 18578
65
64
df = DataFrame ({0 : date_range ('2010' , freq = 'D' , periods = 2 , tz = tz ),
66
65
1 : date_range ('2010' , freq = 'D' , periods = 2 , tz = tz )})
67
- result = df .diff (axis = axis ) # xfails for axis=1 and tz='UTC'
68
66
if axis == 1 :
69
- expected = DataFrame ({0 : pd .TimedeltaIndex (['NaT' , 'NaT' ]),
70
- 1 : pd .TimedeltaIndex (['0 days' , '0 days' ])})
67
+ if tz is None :
68
+ result = df .diff (axis = axis )
69
+ expected = DataFrame ({0 : pd .TimedeltaIndex (['NaT' , 'NaT' ]),
70
+ 1 : pd .TimedeltaIndex (['0 days' ,
71
+ '0 days' ])})
72
+ assert_frame_equal (result , expected )
73
+ else :
74
+ with pytest .raises (NotImplementedError ):
75
+ result = df .diff (axis = axis )
76
+
71
77
else :
78
+ result = df .diff (axis = axis )
72
79
expected = DataFrame ({0 : pd .TimedeltaIndex (['NaT' , '1 days' ]),
73
80
1 : pd .TimedeltaIndex (['NaT' , '1 days' ])})
74
- assert_frame_equal (result , expected )
81
+ assert_frame_equal (result , expected )
75
82
76
83
def test_diff_timedelta (self ):
77
84
# GH 4533
@@ -294,6 +301,28 @@ def test_shift(self):
294
301
result = df .shift (1 , axis = 'columns' )
295
302
assert_frame_equal (result , expected )
296
303
304
+ @pytest .mark .parametrize ('axis' , [0 , 1 ])
305
+ @pytest .mark .parametrize ('tz' , [None , 'UTC' ])
306
+ def test_shift_datetime (self , axis , tz ):
307
+ # GH 18578
308
+ df = DataFrame (date_range ('2010' , freq = 'D' , periods = 2 , tz = tz ))
309
+ df [1 ] = df [0 ]
310
+ if axis == 1 :
311
+ if tz is None :
312
+ result = df .shift (axis = axis )
313
+ expected = DataFrame (DatetimeIndex ([pd .NaT ] * 2 ))
314
+ expected [1 ] = df [1 ]
315
+ assert_frame_equal (result , expected )
316
+ else :
317
+ with pytest .raises (NotImplementedError ):
318
+ result = df .shift (axis = axis )
319
+
320
+ else :
321
+ result = df .shift (axis = axis )
322
+ expected = DataFrame ([pd .NaT , Timestamp ('2010' , tz = tz )])
323
+ expected [1 ] = expected [0 ]
324
+ assert_frame_equal (result , expected )
325
+
297
326
def test_shift_bool (self ):
298
327
df = DataFrame ({'high' : [True , False ],
299
328
'low' : [False , False ]})
0 commit comments