21
21
# --------------------------------------------------------------------------------------
22
22
23
23
24
- def using_pyarrow (dtype ):
25
- return dtype == "string" and dtype .storage == "pyarrow"
26
-
27
-
28
24
def test_contains (any_string_dtype ):
29
25
values = np .array (
30
26
["foo" , np .nan , "fooommm__foo" , "mmm_" , "foommm[_]+bar" ], dtype = np .object_
@@ -458,13 +454,10 @@ def test_replace_mixed_object():
458
454
tm .assert_series_equal (result , expected )
459
455
460
456
461
- def test_replace_unicode (any_string_dtype , performance_warning ):
457
+ def test_replace_unicode (any_string_dtype ):
462
458
ser = Series ([b"abcd,\xc3 \xa0 " .decode ("utf-8" )], dtype = any_string_dtype )
463
459
expected = Series ([b"abcd, \xc3 \xa0 " .decode ("utf-8" )], dtype = any_string_dtype )
464
- with tm .maybe_produces_warning (
465
- performance_warning , using_pyarrow (any_string_dtype )
466
- ):
467
- result = ser .str .replace (r"(?<=\w),(?=\w)" , ", " , flags = re .UNICODE , regex = True )
460
+ result = ser .str .replace (r"(?<=\w),(?=\w)" , ", " , flags = re .UNICODE , regex = True )
468
461
tm .assert_series_equal (result , expected )
469
462
470
463
@@ -478,24 +471,21 @@ def test_replace_wrong_repl_type_raises(any_string_dtype, index_or_series, repl,
478
471
obj .str .replace ("a" , repl )
479
472
480
473
481
- def test_replace_callable (any_string_dtype , performance_warning ):
474
+ def test_replace_callable (any_string_dtype ):
482
475
# GH 15055
483
476
ser = Series (["fooBAD__barBAD" , np .nan ], dtype = any_string_dtype )
484
477
485
478
# test with callable
486
479
repl = lambda m : m .group (0 ).swapcase ()
487
- with tm .maybe_produces_warning (
488
- performance_warning , using_pyarrow (any_string_dtype )
489
- ):
490
- result = ser .str .replace ("[a-z][A-Z]{2}" , repl , n = 2 , regex = True )
480
+ result = ser .str .replace ("[a-z][A-Z]{2}" , repl , n = 2 , regex = True )
491
481
expected = Series (["foObaD__baRbaD" , np .nan ], dtype = any_string_dtype )
492
482
tm .assert_series_equal (result , expected )
493
483
494
484
495
485
@pytest .mark .parametrize (
496
486
"repl" , [lambda : None , lambda m , x : None , lambda m , x , y = None : None ]
497
487
)
498
- def test_replace_callable_raises (any_string_dtype , performance_warning , repl ):
488
+ def test_replace_callable_raises (any_string_dtype , repl ):
499
489
# GH 15055
500
490
values = Series (["fooBAD__barBAD" , np .nan ], dtype = any_string_dtype )
501
491
@@ -504,43 +494,31 @@ def test_replace_callable_raises(any_string_dtype, performance_warning, repl):
504
494
r"((takes)|(missing)) (?(2)from \d+ to )?\d+ "
505
495
r"(?(3)required )positional arguments?"
506
496
)
507
- if not using_pyarrow (any_string_dtype ):
508
- performance_warning = False
509
497
with pytest .raises (TypeError , match = msg ):
510
- with tm .assert_produces_warning (performance_warning ):
511
- values .str .replace ("a" , repl , regex = True )
498
+ values .str .replace ("a" , repl , regex = True )
512
499
513
500
514
- def test_replace_callable_named_groups (any_string_dtype , performance_warning ):
501
+ def test_replace_callable_named_groups (any_string_dtype ):
515
502
# test regex named groups
516
503
ser = Series (["Foo Bar Baz" , np .nan ], dtype = any_string_dtype )
517
504
pat = r"(?P<first>\w+) (?P<middle>\w+) (?P<last>\w+)"
518
505
repl = lambda m : m .group ("middle" ).swapcase ()
519
- with tm .maybe_produces_warning (
520
- performance_warning , using_pyarrow (any_string_dtype )
521
- ):
522
- result = ser .str .replace (pat , repl , regex = True )
506
+ result = ser .str .replace (pat , repl , regex = True )
523
507
expected = Series (["bAR" , np .nan ], dtype = any_string_dtype )
524
508
tm .assert_series_equal (result , expected )
525
509
526
510
527
- def test_replace_compiled_regex (any_string_dtype , performance_warning ):
511
+ def test_replace_compiled_regex (any_string_dtype ):
528
512
# GH 15446
529
513
ser = Series (["fooBAD__barBAD" , np .nan ], dtype = any_string_dtype )
530
514
531
515
# test with compiled regex
532
516
pat = re .compile (r"BAD_*" )
533
- with tm .maybe_produces_warning (
534
- performance_warning , using_pyarrow (any_string_dtype )
535
- ):
536
- result = ser .str .replace (pat , "" , regex = True )
517
+ result = ser .str .replace (pat , "" , regex = True )
537
518
expected = Series (["foobar" , np .nan ], dtype = any_string_dtype )
538
519
tm .assert_series_equal (result , expected )
539
520
540
- with tm .maybe_produces_warning (
541
- performance_warning , using_pyarrow (any_string_dtype )
542
- ):
543
- result = ser .str .replace (pat , "" , n = 1 , regex = True )
521
+ result = ser .str .replace (pat , "" , n = 1 , regex = True )
544
522
expected = Series (["foobarBAD" , np .nan ], dtype = any_string_dtype )
545
523
tm .assert_series_equal (result , expected )
546
524
@@ -557,14 +535,11 @@ def test_replace_compiled_regex_mixed_object():
557
535
tm .assert_series_equal (result , expected )
558
536
559
537
560
- def test_replace_compiled_regex_unicode (any_string_dtype , performance_warning ):
538
+ def test_replace_compiled_regex_unicode (any_string_dtype ):
561
539
ser = Series ([b"abcd,\xc3 \xa0 " .decode ("utf-8" )], dtype = any_string_dtype )
562
540
expected = Series ([b"abcd, \xc3 \xa0 " .decode ("utf-8" )], dtype = any_string_dtype )
563
541
pat = re .compile (r"(?<=\w),(?=\w)" , flags = re .UNICODE )
564
- with tm .maybe_produces_warning (
565
- performance_warning , using_pyarrow (any_string_dtype )
566
- ):
567
- result = ser .str .replace (pat , ", " , regex = True )
542
+ result = ser .str .replace (pat , ", " , regex = True )
568
543
tm .assert_series_equal (result , expected )
569
544
570
545
@@ -586,15 +561,12 @@ def test_replace_compiled_regex_raises(any_string_dtype):
586
561
ser .str .replace (pat , "" , case = True , regex = True )
587
562
588
563
589
- def test_replace_compiled_regex_callable (any_string_dtype , performance_warning ):
564
+ def test_replace_compiled_regex_callable (any_string_dtype ):
590
565
# test with callable
591
566
ser = Series (["fooBAD__barBAD" , np .nan ], dtype = any_string_dtype )
592
567
repl = lambda m : m .group (0 ).swapcase ()
593
568
pat = re .compile ("[a-z][A-Z]{2}" )
594
- with tm .maybe_produces_warning (
595
- performance_warning , using_pyarrow (any_string_dtype )
596
- ):
597
- result = ser .str .replace (pat , repl , n = 2 , regex = True )
569
+ result = ser .str .replace (pat , repl , n = 2 , regex = True )
598
570
expected = Series (["foObaD__baRbaD" , np .nan ], dtype = any_string_dtype )
599
571
tm .assert_series_equal (result , expected )
600
572
@@ -626,7 +598,7 @@ def test_replace_literal_compiled_raises(any_string_dtype):
626
598
ser .str .replace (pat , "" , regex = False )
627
599
628
600
629
- def test_replace_moar (any_string_dtype , performance_warning ):
601
+ def test_replace_moar (any_string_dtype ):
630
602
# PR #1179
631
603
ser = Series (
632
604
["A" , "B" , "C" , "Aaba" , "Baca" , "" , np .nan , "CABA" , "dog" , "cat" ],
@@ -640,10 +612,7 @@ def test_replace_moar(any_string_dtype, performance_warning):
640
612
)
641
613
tm .assert_series_equal (result , expected )
642
614
643
- with tm .maybe_produces_warning (
644
- performance_warning , using_pyarrow (any_string_dtype )
645
- ):
646
- result = ser .str .replace ("A" , "YYY" , case = False )
615
+ result = ser .str .replace ("A" , "YYY" , case = False )
647
616
expected = Series (
648
617
[
649
618
"YYY" ,
@@ -661,10 +630,7 @@ def test_replace_moar(any_string_dtype, performance_warning):
661
630
)
662
631
tm .assert_series_equal (result , expected )
663
632
664
- with tm .maybe_produces_warning (
665
- performance_warning , using_pyarrow (any_string_dtype )
666
- ):
667
- result = ser .str .replace ("^.a|dog" , "XX-XX " , case = False , regex = True )
633
+ result = ser .str .replace ("^.a|dog" , "XX-XX " , case = False , regex = True )
668
634
expected = Series (
669
635
[
670
636
"A" ,
@@ -683,21 +649,15 @@ def test_replace_moar(any_string_dtype, performance_warning):
683
649
tm .assert_series_equal (result , expected )
684
650
685
651
686
- def test_replace_not_case_sensitive_not_regex (any_string_dtype , performance_warning ):
652
+ def test_replace_not_case_sensitive_not_regex (any_string_dtype ):
687
653
# https://github.com/pandas-dev/pandas/issues/41602
688
654
ser = Series (["A." , "a." , "Ab" , "ab" , np .nan ], dtype = any_string_dtype )
689
655
690
- with tm .maybe_produces_warning (
691
- performance_warning , using_pyarrow (any_string_dtype )
692
- ):
693
- result = ser .str .replace ("a" , "c" , case = False , regex = False )
656
+ result = ser .str .replace ("a" , "c" , case = False , regex = False )
694
657
expected = Series (["c." , "c." , "cb" , "cb" , np .nan ], dtype = any_string_dtype )
695
658
tm .assert_series_equal (result , expected )
696
659
697
- with tm .maybe_produces_warning (
698
- performance_warning , using_pyarrow (any_string_dtype )
699
- ):
700
- result = ser .str .replace ("a." , "c." , case = False , regex = False )
660
+ result = ser .str .replace ("a." , "c." , case = False , regex = False )
701
661
expected = Series (["c." , "c." , "Ab" , "ab" , np .nan ], dtype = any_string_dtype )
702
662
tm .assert_series_equal (result , expected )
703
663
@@ -853,7 +813,7 @@ def test_fullmatch_na_kwarg(any_string_dtype):
853
813
tm .assert_series_equal (result , expected )
854
814
855
815
856
- def test_fullmatch_case_kwarg (any_string_dtype , performance_warning ):
816
+ def test_fullmatch_case_kwarg (any_string_dtype ):
857
817
ser = Series (["ab" , "AB" , "abc" , "ABC" ], dtype = any_string_dtype )
858
818
expected_dtype = (
859
819
np .bool_ if is_object_or_nan_string_dtype (any_string_dtype ) else "boolean"
@@ -869,10 +829,7 @@ def test_fullmatch_case_kwarg(any_string_dtype, performance_warning):
869
829
result = ser .str .fullmatch ("ab" , case = False )
870
830
tm .assert_series_equal (result , expected )
871
831
872
- with tm .maybe_produces_warning (
873
- performance_warning , using_pyarrow (any_string_dtype )
874
- ):
875
- result = ser .str .fullmatch ("ab" , flags = re .IGNORECASE )
832
+ result = ser .str .fullmatch ("ab" , flags = re .IGNORECASE )
876
833
tm .assert_series_equal (result , expected )
877
834
878
835
@@ -1046,7 +1003,7 @@ def test_translate_mixed_object():
1046
1003
# --------------------------------------------------------------------------------------
1047
1004
1048
1005
1049
- def test_flags_kwarg (any_string_dtype , performance_warning ):
1006
+ def test_flags_kwarg (any_string_dtype ):
1050
1007
data = {
1051
1008
1052
1009
@@ -1057,17 +1014,13 @@ def test_flags_kwarg(any_string_dtype, performance_warning):
1057
1014
1058
1015
pat = r"([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})"
1059
1016
1060
- use_pyarrow = using_pyarrow (any_string_dtype )
1061
-
1062
1017
result = data .str .extract (pat , flags = re .IGNORECASE , expand = True )
1063
1018
assert result .iloc [0 ].tolist () == ["dave" , "google" , "com" ]
1064
1019
1065
- with tm .maybe_produces_warning (performance_warning , use_pyarrow ):
1066
- result = data .str .match (pat , flags = re .IGNORECASE )
1020
+ result = data .str .match (pat , flags = re .IGNORECASE )
1067
1021
assert result .iloc [0 ]
1068
1022
1069
- with tm .maybe_produces_warning (performance_warning , use_pyarrow ):
1070
- result = data .str .fullmatch (pat , flags = re .IGNORECASE )
1023
+ result = data .str .fullmatch (pat , flags = re .IGNORECASE )
1071
1024
assert result .iloc [0 ]
1072
1025
1073
1026
result = data .str .findall (pat , flags = re .IGNORECASE )
@@ -1077,8 +1030,6 @@ def test_flags_kwarg(any_string_dtype, performance_warning):
1077
1030
assert result .iloc [0 ] == 1
1078
1031
1079
1032
msg = "has match groups"
1080
- with tm .assert_produces_warning (
1081
- UserWarning , match = msg , raise_on_extra_warnings = not use_pyarrow
1082
- ):
1033
+ with tm .assert_produces_warning (UserWarning , match = msg ):
1083
1034
result = data .str .contains (pat , flags = re .IGNORECASE )
1084
1035
assert result .iloc [0 ]
0 commit comments