@@ -222,52 +222,93 @@ def test_series_partial_set(self):
222222 # Regression from GH4825
223223 ser = Series ([0.1 , 0.2 ], index = [1 , 2 ])
224224
225- # loc
225+ # loc equiv to .reindex
226226 expected = Series ([np .nan , 0.2 , np .nan ], index = [3 , 2 , 3 ])
227- result = ser .loc [[3 , 2 , 3 ]]
227+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
228+ result = ser .loc [[3 , 2 , 3 ]]
229+ tm .assert_series_equal (result , expected , check_index_type = True )
230+
231+ result = ser .reindex ([3 , 2 , 3 ])
228232 tm .assert_series_equal (result , expected , check_index_type = True )
229233
230234 expected = Series ([np .nan , 0.2 , np .nan , np .nan ], index = [3 , 2 , 3 , 'x' ])
231- result = ser .loc [[3 , 2 , 3 , 'x' ]]
235+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
236+ result = ser .loc [[3 , 2 , 3 , 'x' ]]
237+ tm .assert_series_equal (result , expected , check_index_type = True )
238+
239+ result = ser .reindex ([3 , 2 , 3 , 'x' ])
232240 tm .assert_series_equal (result , expected , check_index_type = True )
233241
234242 expected = Series ([0.2 , 0.2 , 0.1 ], index = [2 , 2 , 1 ])
235243 result = ser .loc [[2 , 2 , 1 ]]
236244 tm .assert_series_equal (result , expected , check_index_type = True )
237245
238246 expected = Series ([0.2 , 0.2 , np .nan , 0.1 ], index = [2 , 2 , 'x' , 1 ])
239- result = ser .loc [[2 , 2 , 'x' , 1 ]]
247+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
248+ result = ser .loc [[2 , 2 , 'x' , 1 ]]
249+ tm .assert_series_equal (result , expected , check_index_type = True )
250+
251+ result = ser .reindex ([2 , 2 , 'x' , 1 ])
240252 tm .assert_series_equal (result , expected , check_index_type = True )
241253
242254 # raises as nothing in in the index
243255 pytest .raises (KeyError , lambda : ser .loc [[3 , 3 , 3 ]])
244256
245257 expected = Series ([0.2 , 0.2 , np .nan ], index = [2 , 2 , 3 ])
246- result = ser .loc [[2 , 2 , 3 ]]
258+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
259+ result = ser .loc [[2 , 2 , 3 ]]
247260 tm .assert_series_equal (result , expected , check_index_type = True )
248261
262+ result = ser .reindex ([2 , 2 , 3 ])
263+ tm .assert_series_equal (result , expected , check_index_type = True )
264+
265+ s = Series ([0.1 , 0.2 , 0.3 ], index = [1 , 2 , 3 ])
249266 expected = Series ([0.3 , np .nan , np .nan ], index = [3 , 4 , 4 ])
250- result = Series ([0.1 , 0.2 , 0.3 ], index = [1 , 2 , 3 ]).loc [[3 , 4 , 4 ]]
267+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
268+ result = s .loc [[3 , 4 , 4 ]]
251269 tm .assert_series_equal (result , expected , check_index_type = True )
252270
271+ result = s .reindex ([3 , 4 , 4 ])
272+ tm .assert_series_equal (result , expected , check_index_type = True )
273+
274+ s = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
275+ index = [1 , 2 , 3 , 4 ])
253276 expected = Series ([np .nan , 0.3 , 0.3 ], index = [5 , 3 , 3 ])
254- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
255- index = [1 , 2 , 3 , 4 ]).loc [[5 , 3 , 3 ]]
277+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
278+ result = s .loc [[5 , 3 , 3 ]]
279+ tm .assert_series_equal (result , expected , check_index_type = True )
280+
281+ result = s .reindex ([5 , 3 , 3 ])
256282 tm .assert_series_equal (result , expected , check_index_type = True )
257283
284+ s = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
285+ index = [1 , 2 , 3 , 4 ])
258286 expected = Series ([np .nan , 0.4 , 0.4 ], index = [5 , 4 , 4 ])
259- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
260- index = [1 , 2 , 3 , 4 ]).loc [[5 , 4 , 4 ]]
287+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
288+ result = s .loc [[5 , 4 , 4 ]]
289+ tm .assert_series_equal (result , expected , check_index_type = True )
290+
291+ result = s .reindex ([5 , 4 , 4 ])
261292 tm .assert_series_equal (result , expected , check_index_type = True )
262293
294+ s = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
295+ index = [4 , 5 , 6 , 7 ])
263296 expected = Series ([0.4 , np .nan , np .nan ], index = [7 , 2 , 2 ])
264- result = Series ([ 0.1 , 0.2 , 0.3 , 0.4 ],
265- index = [ 4 , 5 , 6 , 7 ]) .loc [[7 , 2 , 2 ]]
297+ with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ):
298+ result = s .loc [[7 , 2 , 2 ]]
266299 tm .assert_series_equal (result , expected , check_index_type = True )
267300
301+ result = s .reindex ([7 , 2 , 2 ])
302+ tm .assert_series_equal (result , expected , check_index_type = True )
303+
304+ s = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
305+ index = [1 , 2 , 3 , 4 ])
268306 expected = Series ([0.4 , np .nan , np .nan ], index = [4 , 5 , 5 ])
269- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
270- index = [1 , 2 , 3 , 4 ]).loc [[4 , 5 , 5 ]]
307+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
308+ result = s .loc [[4 , 5 , 5 ]]
309+ tm .assert_series_equal (result , expected , check_index_type = True )
310+
311+ result = s .reindex ([4 , 5 , 5 ])
271312 tm .assert_series_equal (result , expected , check_index_type = True )
272313
273314 # iloc
@@ -284,13 +325,15 @@ def test_series_partial_set_with_name(self):
284325 # loc
285326 exp_idx = Index ([3 , 2 , 3 ], dtype = 'int64' , name = 'idx' )
286327 expected = Series ([np .nan , 0.2 , np .nan ], index = exp_idx , name = 's' )
287- result = ser .loc [[3 , 2 , 3 ]]
328+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
329+ result = ser .loc [[3 , 2 , 3 ]]
288330 tm .assert_series_equal (result , expected , check_index_type = True )
289331
290332 exp_idx = Index ([3 , 2 , 3 , 'x' ], dtype = 'object' , name = 'idx' )
291333 expected = Series ([np .nan , 0.2 , np .nan , np .nan ], index = exp_idx ,
292334 name = 's' )
293- result = ser .loc [[3 , 2 , 3 , 'x' ]]
335+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
336+ result = ser .loc [[3 , 2 , 3 , 'x' ]]
294337 tm .assert_series_equal (result , expected , check_index_type = True )
295338
296339 exp_idx = Index ([2 , 2 , 1 ], dtype = 'int64' , name = 'idx' )
@@ -300,49 +343,58 @@ def test_series_partial_set_with_name(self):
300343
301344 exp_idx = Index ([2 , 2 , 'x' , 1 ], dtype = 'object' , name = 'idx' )
302345 expected = Series ([0.2 , 0.2 , np .nan , 0.1 ], index = exp_idx , name = 's' )
303- result = ser .loc [[2 , 2 , 'x' , 1 ]]
346+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
347+ result = ser .loc [[2 , 2 , 'x' , 1 ]]
304348 tm .assert_series_equal (result , expected , check_index_type = True )
305349
306350 # raises as nothing in in the index
307351 pytest .raises (KeyError , lambda : ser .loc [[3 , 3 , 3 ]])
308352
309353 exp_idx = Index ([2 , 2 , 3 ], dtype = 'int64' , name = 'idx' )
310354 expected = Series ([0.2 , 0.2 , np .nan ], index = exp_idx , name = 's' )
311- result = ser .loc [[2 , 2 , 3 ]]
355+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
356+ result = ser .loc [[2 , 2 , 3 ]]
312357 tm .assert_series_equal (result , expected , check_index_type = True )
313358
314359 exp_idx = Index ([3 , 4 , 4 ], dtype = 'int64' , name = 'idx' )
315360 expected = Series ([0.3 , np .nan , np .nan ], index = exp_idx , name = 's' )
316361 idx = Index ([1 , 2 , 3 ], dtype = 'int64' , name = 'idx' )
317- result = Series ([0.1 , 0.2 , 0.3 ], index = idx , name = 's' ).loc [[3 , 4 , 4 ]]
362+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
363+ result = Series ([0.1 , 0.2 , 0.3 ],
364+ index = idx ,
365+ name = 's' ).loc [[3 , 4 , 4 ]]
318366 tm .assert_series_equal (result , expected , check_index_type = True )
319367
320368 exp_idx = Index ([5 , 3 , 3 ], dtype = 'int64' , name = 'idx' )
321369 expected = Series ([np .nan , 0.3 , 0.3 ], index = exp_idx , name = 's' )
322370 idx = Index ([1 , 2 , 3 , 4 ], dtype = 'int64' , name = 'idx' )
323- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
324- name = 's' ).loc [[5 , 3 , 3 ]]
371+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
372+ result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
373+ name = 's' ).loc [[5 , 3 , 3 ]]
325374 tm .assert_series_equal (result , expected , check_index_type = True )
326375
327376 exp_idx = Index ([5 , 4 , 4 ], dtype = 'int64' , name = 'idx' )
328377 expected = Series ([np .nan , 0.4 , 0.4 ], index = exp_idx , name = 's' )
329378 idx = Index ([1 , 2 , 3 , 4 ], dtype = 'int64' , name = 'idx' )
330- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
331- name = 's' ).loc [[5 , 4 , 4 ]]
379+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
380+ result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
381+ name = 's' ).loc [[5 , 4 , 4 ]]
332382 tm .assert_series_equal (result , expected , check_index_type = True )
333383
334384 exp_idx = Index ([7 , 2 , 2 ], dtype = 'int64' , name = 'idx' )
335385 expected = Series ([0.4 , np .nan , np .nan ], index = exp_idx , name = 's' )
336386 idx = Index ([4 , 5 , 6 , 7 ], dtype = 'int64' , name = 'idx' )
337- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
338- name = 's' ).loc [[7 , 2 , 2 ]]
387+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
388+ result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
389+ name = 's' ).loc [[7 , 2 , 2 ]]
339390 tm .assert_series_equal (result , expected , check_index_type = True )
340391
341392 exp_idx = Index ([4 , 5 , 5 ], dtype = 'int64' , name = 'idx' )
342393 expected = Series ([0.4 , np .nan , np .nan ], index = exp_idx , name = 's' )
343394 idx = Index ([1 , 2 , 3 , 4 ], dtype = 'int64' , name = 'idx' )
344- result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
345- name = 's' ).loc [[4 , 5 , 5 ]]
395+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
396+ result = Series ([0.1 , 0.2 , 0.3 , 0.4 ], index = idx ,
397+ name = 's' ).loc [[4 , 5 , 5 ]]
346398 tm .assert_series_equal (result , expected , check_index_type = True )
347399
348400 # iloc
0 commit comments