1111 Series ,
1212 _testing as tm ,
1313)
14+ from pandas .tests .strings import object_pyarrow_numpy
1415
1516# --------------------------------------------------------------------------------------
1617# str.contains
@@ -25,7 +26,7 @@ def test_contains(any_string_dtype):
2526 pat = "mmm[_]+"
2627
2728 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"
2930 expected = Series (
3031 np .array ([False , np .nan , True , True , False ], dtype = np .object_ ),
3132 dtype = expected_dtype ,
@@ -44,7 +45,7 @@ def test_contains(any_string_dtype):
4445 dtype = any_string_dtype ,
4546 )
4647 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"
4849 expected = Series (np .array ([False , False , True , True ]), dtype = expected_dtype )
4950 tm .assert_series_equal (result , expected )
5051
@@ -71,14 +72,14 @@ def test_contains(any_string_dtype):
7172 pat = "mmm[_]+"
7273
7374 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"
7576 expected = Series (
7677 np .array ([False , np .nan , True , True ], dtype = np .object_ ), dtype = expected_dtype
7778 )
7879 tm .assert_series_equal (result , expected )
7980
8081 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"
8283 expected = Series (np .array ([False , False , True , True ]), dtype = expected_dtype )
8384 tm .assert_series_equal (result , expected )
8485
@@ -163,7 +164,7 @@ def test_contains_moar(any_string_dtype):
163164 )
164165
165166 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"
167168 expected = Series (
168169 [False , False , False , True , True , False , np .nan , False , False , True ],
169170 dtype = expected_dtype ,
@@ -204,7 +205,7 @@ def test_contains_nan(any_string_dtype):
204205 s = Series ([np .nan , np .nan , np .nan ], dtype = any_string_dtype )
205206
206207 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"
208209 expected = Series ([False , False , False ], dtype = expected_dtype )
209210 tm .assert_series_equal (result , expected )
210211
@@ -220,7 +221,7 @@ def test_contains_nan(any_string_dtype):
220221 tm .assert_series_equal (result , expected )
221222
222223 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"
224225 expected = Series ([np .nan , np .nan , np .nan ], dtype = expected_dtype )
225226 tm .assert_series_equal (result , expected )
226227
@@ -648,7 +649,7 @@ def test_replace_regex_single_character(regex, any_string_dtype):
648649
649650def test_match (any_string_dtype ):
650651 # 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"
652653
653654 values = Series (["fooBAD__barBAD" , np .nan , "foo" ], dtype = any_string_dtype )
654655 result = values .str .match (".*(BAD[_]+).*(BAD)" )
@@ -703,20 +704,20 @@ def test_match_na_kwarg(any_string_dtype):
703704 s = Series (["a" , "b" , np .nan ], dtype = any_string_dtype )
704705
705706 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"
707708 expected = Series ([True , False , False ], dtype = expected_dtype )
708709 tm .assert_series_equal (result , expected )
709710
710711 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"
712713 expected = Series ([True , False , np .nan ], dtype = expected_dtype )
713714 tm .assert_series_equal (result , expected )
714715
715716
716717def test_match_case_kwarg (any_string_dtype ):
717718 values = Series (["ab" , "AB" , "abc" , "ABC" ], dtype = any_string_dtype )
718719 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"
720721 expected = Series ([True , True , True , True ], dtype = expected_dtype )
721722 tm .assert_series_equal (result , expected )
722723
@@ -732,7 +733,7 @@ def test_fullmatch(any_string_dtype):
732733 ["fooBAD__barBAD" , "BAD_BADleroybrown" , np .nan , "foo" ], dtype = any_string_dtype
733734 )
734735 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"
736737 expected = Series ([True , False , np .nan , False ], dtype = expected_dtype )
737738 tm .assert_series_equal (result , expected )
738739
@@ -742,14 +743,14 @@ def test_fullmatch_na_kwarg(any_string_dtype):
742743 ["fooBAD__barBAD" , "BAD_BADleroybrown" , np .nan , "foo" ], dtype = any_string_dtype
743744 )
744745 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"
746747 expected = Series ([True , False , False , False ], dtype = expected_dtype )
747748 tm .assert_series_equal (result , expected )
748749
749750
750751def test_fullmatch_case_kwarg (any_string_dtype ):
751752 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"
753754
754755 expected = Series ([True , False , False , False ], dtype = expected_dtype )
755756
@@ -877,7 +878,7 @@ def test_find_nan(any_string_dtype):
877878 ser = Series (
878879 ["ABCDEFG" , np .nan , "DEFGHIJEF" , np .nan , "XXXX" ], dtype = any_string_dtype
879880 )
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"
881882
882883 result = ser .str .find ("EF" )
883884 expected = Series ([4 , np .nan , 1 , np .nan , - 1 ], dtype = expected_dtype )
0 commit comments