@@ -169,3 +169,48 @@ def test_diff_sparse(self):
169169 )
170170
171171 tm .assert_frame_equal (result , expected )
172+
173+ @pytest .mark .parametrize (
174+ "axis,expected" ,
175+ [
176+ (
177+ 0 ,
178+ pd .DataFrame (
179+ {
180+ "a" : [np .nan , 0 , 1 , 0 , np .nan , np .nan , np .nan , 0 ],
181+ "b" : [np .nan , 1 , np .nan , np .nan , - 2 , 1 , np .nan , np .nan ],
182+ "c" : np .repeat (np .nan , 8 ),
183+ "d" : [np .nan , 3 , 5 , 7 , 9 , 11 , 13 , 15 ],
184+ },
185+ dtype = "Int64" ,
186+ ),
187+ ),
188+ (
189+ 1 ,
190+ pd .DataFrame (
191+ {
192+ "a" : np .repeat (np .nan , 8 ),
193+ "b" : [0 , 1 , np .nan , 1 , np .nan , np .nan , np .nan , 0 ],
194+ "c" : np .repeat (np .nan , 8 ),
195+ "d" : np .repeat (np .nan , 8 ),
196+ },
197+ dtype = "Int64" ,
198+ ),
199+ ),
200+ ],
201+ )
202+ def test_diff_integer_na (self , axis , expected ):
203+ # GH#24171 IntegerNA Support for DataFrame.diff()
204+ df = pd .DataFrame (
205+ {
206+ "a" : np .repeat ([0 , 1 , np .nan , 2 ], 2 ),
207+ "b" : np .tile ([0 , 1 , np .nan , 2 ], 2 ),
208+ "c" : np .repeat (np .nan , 8 ),
209+ "d" : np .arange (1 , 9 ) ** 2 ,
210+ },
211+ dtype = "Int64" ,
212+ )
213+
214+ # Test case for default behaviour of diff
215+ result = df .diff (axis = axis )
216+ tm .assert_frame_equal (result , expected )
0 commit comments