@@ -397,42 +397,34 @@ def test_deprecated_match(self):
397
397
# Old match behavior, deprecated (but still default) in 0.13
398
398
values = Series (['fooBAD__barBAD' , NA , 'foo' ])
399
399
400
- with warnings .catch_warnings (record = True ) as w :
401
- warnings .simplefilter ('always' )
400
+ with tm .assert_produces_warning ():
402
401
result = values .str .match ('.*(BAD[_]+).*(BAD)' )
403
- assert issubclass (w [- 1 ].category , UserWarning )
404
402
exp = Series ([('BAD__' , 'BAD' ), NA , []])
405
403
tm .assert_series_equal (result , exp )
406
404
407
405
# mixed
408
406
mixed = Series (['aBAD_BAD' , NA , 'BAD_b_BAD' , True , datetime .today (),
409
407
'foo' , None , 1 , 2. ])
410
408
411
- with warnings .catch_warnings (record = True ) as w :
412
- warnings .simplefilter ('always' )
409
+ with tm .assert_produces_warning ():
413
410
rs = Series (mixed ).str .match ('.*(BAD[_]+).*(BAD)' )
414
- assert issubclass (w [- 1 ].category , UserWarning )
415
411
xp = [('BAD_' , 'BAD' ), NA , ('BAD_' , 'BAD' ), NA , NA , [], NA , NA , NA ]
416
412
tm .assert_isinstance (rs , Series )
417
413
tm .assert_almost_equal (rs , xp )
418
414
419
415
# unicode
420
416
values = Series ([u ('fooBAD__barBAD' ), NA , u ('foo' )])
421
417
422
- with warnings .catch_warnings (record = True ) as w :
423
- warnings .simplefilter ('always' )
418
+ with tm .assert_produces_warning ():
424
419
result = values .str .match ('.*(BAD[_]+).*(BAD)' )
425
- assert issubclass (w [- 1 ].category , UserWarning )
426
420
exp = Series ([(u ('BAD__' ), u ('BAD' )), NA , []])
427
421
tm .assert_series_equal (result , exp )
428
422
429
423
def test_match (self ):
430
424
# New match behavior introduced in 0.13
431
425
values = Series (['fooBAD__barBAD' , NA , 'foo' ])
432
- with warnings .catch_warnings (record = True ) as w :
433
- warnings .simplefilter ('always' )
426
+ with tm .assert_produces_warning ():
434
427
result = values .str .match ('.*(BAD[_]+).*(BAD)' , as_indexer = True )
435
- assert issubclass (w [- 1 ].category , UserWarning )
436
428
exp = Series ([True , NA , False ])
437
429
tm .assert_series_equal (result , exp )
438
430
@@ -447,21 +439,17 @@ def test_match(self):
447
439
mixed = Series (['aBAD_BAD' , NA , 'BAD_b_BAD' , True , datetime .today (),
448
440
'foo' , None , 1 , 2. ])
449
441
450
- with warnings .catch_warnings (record = True ) as w :
451
- warnings .simplefilter ('always' )
442
+ with tm .assert_produces_warning ():
452
443
rs = Series (mixed ).str .match ('.*(BAD[_]+).*(BAD)' , as_indexer = True )
453
- assert issubclass (w [- 1 ].category , UserWarning )
454
444
xp = [True , NA , True , NA , NA , False , NA , NA , NA ]
455
445
tm .assert_isinstance (rs , Series )
456
446
tm .assert_almost_equal (rs , xp )
457
447
458
448
# unicode
459
449
values = Series ([u ('fooBAD__barBAD' ), NA , u ('foo' )])
460
450
461
- with warnings .catch_warnings (record = True ) as w :
462
- warnings .simplefilter ('always' )
451
+ with tm .assert_produces_warning ():
463
452
result = values .str .match ('.*(BAD[_]+).*(BAD)' , as_indexer = True )
464
- assert issubclass (w [- 1 ].category , UserWarning )
465
453
exp = Series ([True , NA , False ])
466
454
tm .assert_series_equal (result , exp )
467
455
0 commit comments