@@ -222,52 +222,93 @@ def test_series_partial_set(self):
222
222
# Regression from GH4825
223
223
ser = Series ([0.1 , 0.2 ], index = [1 , 2 ])
224
224
225
- # loc
225
+ # loc equiv to .reindex
226
226
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 ])
228
232
tm .assert_series_equal (result , expected , check_index_type = True )
229
233
230
234
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' ])
232
240
tm .assert_series_equal (result , expected , check_index_type = True )
233
241
234
242
expected = Series ([0.2 , 0.2 , 0.1 ], index = [2 , 2 , 1 ])
235
243
result = ser .loc [[2 , 2 , 1 ]]
236
244
tm .assert_series_equal (result , expected , check_index_type = True )
237
245
238
246
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 ])
240
252
tm .assert_series_equal (result , expected , check_index_type = True )
241
253
242
254
# raises as nothing in in the index
243
255
pytest .raises (KeyError , lambda : ser .loc [[3 , 3 , 3 ]])
244
256
245
257
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 ]]
247
260
tm .assert_series_equal (result , expected , check_index_type = True )
248
261
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 ])
249
266
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 ]]
251
269
tm .assert_series_equal (result , expected , check_index_type = True )
252
270
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 ])
253
276
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 ])
256
282
tm .assert_series_equal (result , expected , check_index_type = True )
257
283
284
+ s = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
285
+ index = [1 , 2 , 3 , 4 ])
258
286
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 ])
261
292
tm .assert_series_equal (result , expected , check_index_type = True )
262
293
294
+ s = Series ([0.1 , 0.2 , 0.3 , 0.4 ],
295
+ index = [4 , 5 , 6 , 7 ])
263
296
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 ]]
266
299
tm .assert_series_equal (result , expected , check_index_type = True )
267
300
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 ])
268
306
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 ])
271
312
tm .assert_series_equal (result , expected , check_index_type = True )
272
313
273
314
# iloc
@@ -284,13 +325,15 @@ def test_series_partial_set_with_name(self):
284
325
# loc
285
326
exp_idx = Index ([3 , 2 , 3 ], dtype = 'int64' , name = 'idx' )
286
327
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 ]]
288
330
tm .assert_series_equal (result , expected , check_index_type = True )
289
331
290
332
exp_idx = Index ([3 , 2 , 3 , 'x' ], dtype = 'object' , name = 'idx' )
291
333
expected = Series ([np .nan , 0.2 , np .nan , np .nan ], index = exp_idx ,
292
334
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' ]]
294
337
tm .assert_series_equal (result , expected , check_index_type = True )
295
338
296
339
exp_idx = Index ([2 , 2 , 1 ], dtype = 'int64' , name = 'idx' )
@@ -300,49 +343,58 @@ def test_series_partial_set_with_name(self):
300
343
301
344
exp_idx = Index ([2 , 2 , 'x' , 1 ], dtype = 'object' , name = 'idx' )
302
345
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 ]]
304
348
tm .assert_series_equal (result , expected , check_index_type = True )
305
349
306
350
# raises as nothing in in the index
307
351
pytest .raises (KeyError , lambda : ser .loc [[3 , 3 , 3 ]])
308
352
309
353
exp_idx = Index ([2 , 2 , 3 ], dtype = 'int64' , name = 'idx' )
310
354
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 ]]
312
357
tm .assert_series_equal (result , expected , check_index_type = True )
313
358
314
359
exp_idx = Index ([3 , 4 , 4 ], dtype = 'int64' , name = 'idx' )
315
360
expected = Series ([0.3 , np .nan , np .nan ], index = exp_idx , name = 's' )
316
361
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 ]]
318
366
tm .assert_series_equal (result , expected , check_index_type = True )
319
367
320
368
exp_idx = Index ([5 , 3 , 3 ], dtype = 'int64' , name = 'idx' )
321
369
expected = Series ([np .nan , 0.3 , 0.3 ], index = exp_idx , name = 's' )
322
370
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 ]]
325
374
tm .assert_series_equal (result , expected , check_index_type = True )
326
375
327
376
exp_idx = Index ([5 , 4 , 4 ], dtype = 'int64' , name = 'idx' )
328
377
expected = Series ([np .nan , 0.4 , 0.4 ], index = exp_idx , name = 's' )
329
378
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 ]]
332
382
tm .assert_series_equal (result , expected , check_index_type = True )
333
383
334
384
exp_idx = Index ([7 , 2 , 2 ], dtype = 'int64' , name = 'idx' )
335
385
expected = Series ([0.4 , np .nan , np .nan ], index = exp_idx , name = 's' )
336
386
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 ]]
339
390
tm .assert_series_equal (result , expected , check_index_type = True )
340
391
341
392
exp_idx = Index ([4 , 5 , 5 ], dtype = 'int64' , name = 'idx' )
342
393
expected = Series ([0.4 , np .nan , np .nan ], index = exp_idx , name = 's' )
343
394
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 ]]
346
398
tm .assert_series_equal (result , expected , check_index_type = True )
347
399
348
400
# iloc
0 commit comments