11
11
Series ,
12
12
_testing as tm ,
13
13
)
14
+ from pandas .tests .strings import object_pyarrow_numpy
14
15
15
16
# --------------------------------------------------------------------------------------
16
17
# str.contains
@@ -25,7 +26,7 @@ def test_contains(any_string_dtype):
25
26
pat = "mmm[_]+"
26
27
27
28
result = values .str .contains (pat )
28
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
29
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
29
30
expected = Series (
30
31
np .array ([False , np .nan , True , True , False ], dtype = np .object_ ),
31
32
dtype = expected_dtype ,
@@ -44,7 +45,7 @@ def test_contains(any_string_dtype):
44
45
dtype = any_string_dtype ,
45
46
)
46
47
result = values .str .contains (pat )
47
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
48
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
48
49
expected = Series (np .array ([False , False , True , True ]), dtype = expected_dtype )
49
50
tm .assert_series_equal (result , expected )
50
51
@@ -71,14 +72,14 @@ def test_contains(any_string_dtype):
71
72
pat = "mmm[_]+"
72
73
73
74
result = values .str .contains (pat )
74
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
75
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
75
76
expected = Series (
76
77
np .array ([False , np .nan , True , True ], dtype = np .object_ ), dtype = expected_dtype
77
78
)
78
79
tm .assert_series_equal (result , expected )
79
80
80
81
result = values .str .contains (pat , na = False )
81
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
82
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
82
83
expected = Series (np .array ([False , False , True , True ]), dtype = expected_dtype )
83
84
tm .assert_series_equal (result , expected )
84
85
@@ -163,7 +164,7 @@ def test_contains_moar(any_string_dtype):
163
164
)
164
165
165
166
result = s .str .contains ("a" )
166
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
167
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
167
168
expected = Series (
168
169
[False , False , False , True , True , False , np .nan , False , False , True ],
169
170
dtype = expected_dtype ,
@@ -204,7 +205,7 @@ def test_contains_nan(any_string_dtype):
204
205
s = Series ([np .nan , np .nan , np .nan ], dtype = any_string_dtype )
205
206
206
207
result = s .str .contains ("foo" , na = False )
207
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
208
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
208
209
expected = Series ([False , False , False ], dtype = expected_dtype )
209
210
tm .assert_series_equal (result , expected )
210
211
@@ -220,7 +221,7 @@ def test_contains_nan(any_string_dtype):
220
221
tm .assert_series_equal (result , expected )
221
222
222
223
result = s .str .contains ("foo" )
223
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
224
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
224
225
expected = Series ([np .nan , np .nan , np .nan ], dtype = expected_dtype )
225
226
tm .assert_series_equal (result , expected )
226
227
@@ -648,7 +649,7 @@ def test_replace_regex_single_character(regex, any_string_dtype):
648
649
649
650
def test_match (any_string_dtype ):
650
651
# New match behavior introduced in 0.13
651
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
652
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
652
653
653
654
values = Series (["fooBAD__barBAD" , np .nan , "foo" ], dtype = any_string_dtype )
654
655
result = values .str .match (".*(BAD[_]+).*(BAD)" )
@@ -703,20 +704,20 @@ def test_match_na_kwarg(any_string_dtype):
703
704
s = Series (["a" , "b" , np .nan ], dtype = any_string_dtype )
704
705
705
706
result = s .str .match ("a" , na = False )
706
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
707
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
707
708
expected = Series ([True , False , False ], dtype = expected_dtype )
708
709
tm .assert_series_equal (result , expected )
709
710
710
711
result = s .str .match ("a" )
711
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
712
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
712
713
expected = Series ([True , False , np .nan ], dtype = expected_dtype )
713
714
tm .assert_series_equal (result , expected )
714
715
715
716
716
717
def test_match_case_kwarg (any_string_dtype ):
717
718
values = Series (["ab" , "AB" , "abc" , "ABC" ], dtype = any_string_dtype )
718
719
result = values .str .match ("ab" , case = False )
719
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
720
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
720
721
expected = Series ([True , True , True , True ], dtype = expected_dtype )
721
722
tm .assert_series_equal (result , expected )
722
723
@@ -732,7 +733,7 @@ def test_fullmatch(any_string_dtype):
732
733
["fooBAD__barBAD" , "BAD_BADleroybrown" , np .nan , "foo" ], dtype = any_string_dtype
733
734
)
734
735
result = ser .str .fullmatch (".*BAD[_]+.*BAD" )
735
- expected_dtype = "object" if any_string_dtype == "object" else "boolean"
736
+ expected_dtype = "object" if any_string_dtype in object_pyarrow_numpy else "boolean"
736
737
expected = Series ([True , False , np .nan , False ], dtype = expected_dtype )
737
738
tm .assert_series_equal (result , expected )
738
739
@@ -742,14 +743,14 @@ def test_fullmatch_na_kwarg(any_string_dtype):
742
743
["fooBAD__barBAD" , "BAD_BADleroybrown" , np .nan , "foo" ], dtype = any_string_dtype
743
744
)
744
745
result = ser .str .fullmatch (".*BAD[_]+.*BAD" , na = False )
745
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
746
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
746
747
expected = Series ([True , False , False , False ], dtype = expected_dtype )
747
748
tm .assert_series_equal (result , expected )
748
749
749
750
750
751
def test_fullmatch_case_kwarg (any_string_dtype ):
751
752
ser = Series (["ab" , "AB" , "abc" , "ABC" ], dtype = any_string_dtype )
752
- expected_dtype = np .bool_ if any_string_dtype == "object" else "boolean"
753
+ expected_dtype = np .bool_ if any_string_dtype in object_pyarrow_numpy else "boolean"
753
754
754
755
expected = Series ([True , False , False , False ], dtype = expected_dtype )
755
756
@@ -877,7 +878,7 @@ def test_find_nan(any_string_dtype):
877
878
ser = Series (
878
879
["ABCDEFG" , np .nan , "DEFGHIJEF" , np .nan , "XXXX" ], dtype = any_string_dtype
879
880
)
880
- expected_dtype = np .float64 if any_string_dtype == "object" else "Int64"
881
+ expected_dtype = np .float64 if any_string_dtype in object_pyarrow_numpy else "Int64"
881
882
882
883
result = ser .str .find ("EF" )
883
884
expected = Series ([4 , np .nan , 1 , np .nan , - 1 ], dtype = expected_dtype )
0 commit comments