@@ -21,19 +21,22 @@ def test_append_multiindex(self, multiindex_dataframe_random_data, frame_or_seri
21
21
a = obj [:5 ]
22
22
b = obj [5 :]
23
23
24
- result = a .append (b )
24
+ with tm .assert_produces_warning (FutureWarning ):
25
+ result = a .append (b )
25
26
tm .assert_equal (result , obj )
26
27
27
28
def test_append_empty_list (self ):
28
29
# GH 28769
29
30
df = DataFrame ()
30
- result = df .append ([])
31
+ with tm .assert_produces_warning (FutureWarning ):
32
+ result = df .append ([])
31
33
expected = df
32
34
tm .assert_frame_equal (result , expected )
33
35
assert result is not df
34
36
35
37
df = DataFrame (np .random .randn (5 , 4 ), columns = ["foo" , "bar" , "baz" , "qux" ])
36
- result = df .append ([])
38
+ with tm .assert_produces_warning (FutureWarning ):
39
+ result = df .append ([])
37
40
expected = df
38
41
tm .assert_frame_equal (result , expected )
39
42
assert result is not df # .append() should return a new object
@@ -43,57 +46,69 @@ def test_append_series_dict(self):
43
46
44
47
series = df .loc [4 ]
45
48
msg = "Indexes have overlapping values"
46
- with pytest .raises (ValueError , match = msg ):
49
+ with pytest .raises (ValueError , match = msg ), tm .assert_produces_warning (
50
+ FutureWarning
51
+ ):
47
52
df .append (series , verify_integrity = True )
48
53
49
54
series .name = None
50
55
msg = "Can only append a Series if ignore_index=True"
51
- with pytest .raises (TypeError , match = msg ):
56
+ with pytest .raises (TypeError , match = msg ), tm .assert_produces_warning (
57
+ FutureWarning
58
+ ):
52
59
df .append (series , verify_integrity = True )
53
60
54
- result = df .append (series [::- 1 ], ignore_index = True )
55
- expected = df .append (
56
- DataFrame ({0 : series [::- 1 ]}, index = df .columns ).T , ignore_index = True
57
- )
61
+ with tm .assert_produces_warning (FutureWarning ):
62
+ result = df .append (series [::- 1 ], ignore_index = True )
63
+ expected = df .append (
64
+ DataFrame ({0 : series [::- 1 ]}, index = df .columns ).T , ignore_index = True
65
+ )
58
66
tm .assert_frame_equal (result , expected )
59
67
60
68
# dict
61
- result = df .append (series .to_dict (), ignore_index = True )
69
+ with tm .assert_produces_warning (FutureWarning ):
70
+ result = df .append (series .to_dict (), ignore_index = True )
62
71
tm .assert_frame_equal (result , expected )
63
72
64
- result = df .append (series [::- 1 ][:3 ], ignore_index = True )
65
- expected = df .append (
66
- DataFrame ({0 : series [::- 1 ][:3 ]}).T , ignore_index = True , sort = True
67
- )
73
+ with tm .assert_produces_warning (FutureWarning ):
74
+ result = df .append (series [::- 1 ][:3 ], ignore_index = True )
75
+ expected = df .append (
76
+ DataFrame ({0 : series [::- 1 ][:3 ]}).T , ignore_index = True , sort = True
77
+ )
68
78
tm .assert_frame_equal (result , expected .loc [:, result .columns ])
69
79
70
80
msg = "Can only append a dict if ignore_index=True"
71
- with pytest .raises (TypeError , match = msg ):
81
+ with pytest .raises (TypeError , match = msg ), tm .assert_produces_warning (
82
+ FutureWarning
83
+ ):
72
84
df .append (series .to_dict ())
73
85
74
86
# can append when name set
75
87
row = df .loc [4 ]
76
88
row .name = 5
77
- result = df .append (row )
78
- expected = df .append (df [- 1 :], ignore_index = True )
89
+ with tm .assert_produces_warning (FutureWarning ):
90
+ result = df .append (row )
91
+ expected = df .append (df [- 1 :], ignore_index = True )
79
92
tm .assert_frame_equal (result , expected )
80
93
81
94
def test_append_list_of_series_dicts (self ):
82
95
df = DataFrame (np .random .randn (5 , 4 ), columns = ["foo" , "bar" , "baz" , "qux" ])
83
96
84
97
dicts = [x .to_dict () for idx , x in df .iterrows ()]
85
98
86
- result = df .append (dicts , ignore_index = True )
87
- expected = df .append (df , ignore_index = True )
99
+ with tm .assert_produces_warning (FutureWarning ):
100
+ result = df .append (dicts , ignore_index = True )
101
+ expected = df .append (df , ignore_index = True )
88
102
tm .assert_frame_equal (result , expected )
89
103
90
104
# different columns
91
105
dicts = [
92
106
{"foo" : 1 , "bar" : 2 , "baz" : 3 , "peekaboo" : 4 },
93
107
{"foo" : 5 , "bar" : 6 , "baz" : 7 , "peekaboo" : 8 },
94
108
]
95
- result = df .append (dicts , ignore_index = True , sort = True )
96
- expected = df .append (DataFrame (dicts ), ignore_index = True , sort = True )
109
+ with tm .assert_produces_warning (FutureWarning ):
110
+ result = df .append (dicts , ignore_index = True , sort = True )
111
+ expected = df .append (DataFrame (dicts ), ignore_index = True , sort = True )
97
112
tm .assert_frame_equal (result , expected )
98
113
99
114
def test_append_list_retain_index_name (self ):
@@ -109,11 +124,13 @@ def test_append_list_retain_index_name(self):
109
124
)
110
125
111
126
# append series
112
- result = df .append (serc )
127
+ with tm .assert_produces_warning (FutureWarning ):
128
+ result = df .append (serc )
113
129
tm .assert_frame_equal (result , expected )
114
130
115
131
# append list of series
116
- result = df .append ([serc ])
132
+ with tm .assert_produces_warning (FutureWarning ):
133
+ result = df .append ([serc ])
117
134
tm .assert_frame_equal (result , expected )
118
135
119
136
def test_append_missing_cols (self ):
@@ -124,39 +141,43 @@ def test_append_missing_cols(self):
124
141
df = DataFrame (np .random .randn (5 , 4 ), columns = ["foo" , "bar" , "baz" , "qux" ])
125
142
126
143
dicts = [{"foo" : 9 }, {"bar" : 10 }]
127
- with tm .assert_produces_warning (None ):
144
+ with tm .assert_produces_warning (FutureWarning ):
128
145
result = df .append (dicts , ignore_index = True , sort = True )
129
146
130
- expected = df .append (DataFrame (dicts ), ignore_index = True , sort = True )
147
+ expected = df .append (DataFrame (dicts ), ignore_index = True , sort = True )
131
148
tm .assert_frame_equal (result , expected )
132
149
133
150
def test_append_empty_dataframe (self ):
134
151
135
152
# Empty df append empty df
136
153
df1 = DataFrame ()
137
154
df2 = DataFrame ()
138
- result = df1 .append (df2 )
155
+ with tm .assert_produces_warning (FutureWarning ):
156
+ result = df1 .append (df2 )
139
157
expected = df1 .copy ()
140
158
tm .assert_frame_equal (result , expected )
141
159
142
160
# Non-empty df append empty df
143
161
df1 = DataFrame (np .random .randn (5 , 2 ))
144
162
df2 = DataFrame ()
145
- result = df1 .append (df2 )
163
+ with tm .assert_produces_warning (FutureWarning ):
164
+ result = df1 .append (df2 )
146
165
expected = df1 .copy ()
147
166
tm .assert_frame_equal (result , expected )
148
167
149
168
# Empty df with columns append empty df
150
169
df1 = DataFrame (columns = ["bar" , "foo" ])
151
170
df2 = DataFrame ()
152
- result = df1 .append (df2 )
171
+ with tm .assert_produces_warning (FutureWarning ):
172
+ result = df1 .append (df2 )
153
173
expected = df1 .copy ()
154
174
tm .assert_frame_equal (result , expected )
155
175
156
176
# Non-Empty df with columns append empty df
157
177
df1 = DataFrame (np .random .randn (5 , 2 ), columns = ["bar" , "foo" ])
158
178
df2 = DataFrame ()
159
- result = df1 .append (df2 )
179
+ with tm .assert_produces_warning (FutureWarning ):
180
+ result = df1 .append (df2 )
160
181
expected = df1 .copy ()
161
182
tm .assert_frame_equal (result , expected )
162
183
@@ -168,19 +189,22 @@ def test_append_dtypes(self):
168
189
169
190
df1 = DataFrame ({"bar" : Timestamp ("20130101" )}, index = range (5 ))
170
191
df2 = DataFrame ()
171
- result = df1 .append (df2 )
192
+ with tm .assert_produces_warning (FutureWarning ):
193
+ result = df1 .append (df2 )
172
194
expected = df1 .copy ()
173
195
tm .assert_frame_equal (result , expected )
174
196
175
197
df1 = DataFrame ({"bar" : Timestamp ("20130101" )}, index = range (1 ))
176
198
df2 = DataFrame ({"bar" : "foo" }, index = range (1 , 2 ))
177
- result = df1 .append (df2 )
199
+ with tm .assert_produces_warning (FutureWarning ):
200
+ result = df1 .append (df2 )
178
201
expected = DataFrame ({"bar" : [Timestamp ("20130101" ), "foo" ]})
179
202
tm .assert_frame_equal (result , expected )
180
203
181
204
df1 = DataFrame ({"bar" : Timestamp ("20130101" )}, index = range (1 ))
182
205
df2 = DataFrame ({"bar" : np .nan }, index = range (1 , 2 ))
183
- result = df1 .append (df2 )
206
+ with tm .assert_produces_warning (FutureWarning ):
207
+ result = df1 .append (df2 )
184
208
expected = DataFrame (
185
209
{"bar" : Series ([Timestamp ("20130101" ), np .nan ], dtype = "M8[ns]" )}
186
210
)
@@ -189,7 +213,8 @@ def test_append_dtypes(self):
189
213
190
214
df1 = DataFrame ({"bar" : Timestamp ("20130101" )}, index = range (1 ))
191
215
df2 = DataFrame ({"bar" : np .nan }, index = range (1 , 2 ), dtype = object )
192
- result = df1 .append (df2 )
216
+ with tm .assert_produces_warning (FutureWarning ):
217
+ result = df1 .append (df2 )
193
218
expected = DataFrame (
194
219
{"bar" : Series ([Timestamp ("20130101" ), np .nan ], dtype = "M8[ns]" )}
195
220
)
@@ -198,7 +223,8 @@ def test_append_dtypes(self):
198
223
199
224
df1 = DataFrame ({"bar" : np .nan }, index = range (1 ))
200
225
df2 = DataFrame ({"bar" : Timestamp ("20130101" )}, index = range (1 , 2 ))
201
- result = df1 .append (df2 )
226
+ with tm .assert_produces_warning (FutureWarning ):
227
+ result = df1 .append (df2 )
202
228
expected = DataFrame (
203
229
{"bar" : Series ([np .nan , Timestamp ("20130101" )], dtype = "M8[ns]" )}
204
230
)
@@ -207,7 +233,8 @@ def test_append_dtypes(self):
207
233
208
234
df1 = DataFrame ({"bar" : Timestamp ("20130101" )}, index = range (1 ))
209
235
df2 = DataFrame ({"bar" : 1 }, index = range (1 , 2 ), dtype = object )
210
- result = df1 .append (df2 )
236
+ with tm .assert_produces_warning (FutureWarning ):
237
+ result = df1 .append (df2 )
211
238
expected = DataFrame ({"bar" : Series ([Timestamp ("20130101" ), 1 ])})
212
239
tm .assert_frame_equal (result , expected )
213
240
@@ -218,7 +245,8 @@ def test_append_timestamps_aware_or_naive(self, tz_naive_fixture, timestamp):
218
245
# GH 30238
219
246
tz = tz_naive_fixture
220
247
df = DataFrame ([Timestamp (timestamp , tz = tz )])
221
- result = df .append (df .iloc [0 ]).iloc [- 1 ]
248
+ with tm .assert_produces_warning (FutureWarning ):
249
+ result = df .append (df .iloc [0 ]).iloc [- 1 ]
222
250
expected = Series (Timestamp (timestamp , tz = tz ), name = 0 )
223
251
tm .assert_series_equal (result , expected )
224
252
@@ -234,7 +262,8 @@ def test_append_timestamps_aware_or_naive(self, tz_naive_fixture, timestamp):
234
262
)
235
263
def test_other_dtypes (self , data , dtype ):
236
264
df = DataFrame (data , dtype = dtype )
237
- result = df .append (df .iloc [0 ]).iloc [- 1 ]
265
+ with tm .assert_produces_warning (FutureWarning ):
266
+ result = df .append (df .iloc [0 ]).iloc [- 1 ]
238
267
expected = Series (data , name = 0 , dtype = dtype )
239
268
tm .assert_series_equal (result , expected )
240
269
@@ -249,7 +278,8 @@ def test_append_numpy_bug_1681(self, dtype):
249
278
df = DataFrame ()
250
279
other = DataFrame ({"A" : "foo" , "B" : index }, index = index )
251
280
252
- result = df .append (other )
281
+ with tm .assert_produces_warning (FutureWarning ):
282
+ result = df .append (other )
253
283
assert (result ["B" ] == index ).all ()
254
284
255
285
@pytest .mark .filterwarnings ("ignore:The values in the array:RuntimeWarning" )
@@ -264,7 +294,8 @@ def test_multiindex_column_append_multiple(self):
264
294
df2 = df .copy ()
265
295
for i in range (1 , 10 ):
266
296
df [i , "colA" ] = 10
267
- df = df .append (df2 , ignore_index = True )
297
+ with tm .assert_produces_warning (FutureWarning ):
298
+ df = df .append (df2 , ignore_index = True )
268
299
result = df ["multi" ]
269
300
expected = DataFrame (
270
301
{"col1" : [1 , 2 , 3 ] * (i + 1 ), "col2" : [11 , 12 , 13 ] * (i + 1 )}
0 commit comments