@@ -29,6 +29,8 @@ def assert_series_or_index_equal(left, right):
29
29
("decode" , ("UTF-8" ,), {}),
30
30
("encode" , ("UTF-8" ,), {}),
31
31
("endswith" , ("a" ,), {}),
32
+ ("endswith" , ("a" ,), {"na" : True }),
33
+ ("endswith" , ("a" ,), {"na" : False }),
32
34
("extract" , ("([a-z]*)" ,), {"expand" : False }),
33
35
("extract" , ("([a-z]*)" ,), {"expand" : True }),
34
36
("extractall" , ("([a-z]*)" ,), {}),
@@ -58,6 +60,8 @@ def assert_series_or_index_equal(left, right):
58
60
("split" , (" " ,), {"expand" : False }),
59
61
("split" , (" " ,), {"expand" : True }),
60
62
("startswith" , ("a" ,), {}),
63
+ ("startswith" , ("a" ,), {"na" : True }),
64
+ ("startswith" , ("a" ,), {"na" : False }),
61
65
# translating unicode points of "a" to "d"
62
66
("translate" , ({97 : 100 },), {}),
63
67
("wrap" , (2 ,), {}),
@@ -838,15 +842,23 @@ def test_contains_for_object_category(self):
838
842
expected = Series ([True , False , False , True , False ])
839
843
tm .assert_series_equal (result , expected )
840
844
841
- def test_startswith (self ):
842
- values = Series (["om" , np .nan , "foo_nom" , "nom" , "bar_foo" , np .nan , "foo" ])
845
+ @pytest .mark .parametrize ("dtype" , [None , "category" ])
846
+ @pytest .mark .parametrize ("null_value" , [None , np .nan , pd .NA ])
847
+ @pytest .mark .parametrize ("na" , [True , False ])
848
+ def test_startswith (self , dtype , null_value , na ):
849
+ # add category dtype parametrizations for GH-36241
850
+ values = Series (
851
+ ["om" , null_value , "foo_nom" , "nom" , "bar_foo" , null_value , "foo" ],
852
+ dtype = dtype ,
853
+ )
843
854
844
855
result = values .str .startswith ("foo" )
845
856
exp = Series ([False , np .nan , True , False , False , np .nan , True ])
846
857
tm .assert_series_equal (result , exp )
847
858
848
- result = values .str .startswith ("foo" , na = True )
849
- tm .assert_series_equal (result , exp .fillna (True ).astype (bool ))
859
+ result = values .str .startswith ("foo" , na = na )
860
+ exp = Series ([False , na , True , False , False , na , True ])
861
+ tm .assert_series_equal (result , exp )
850
862
851
863
# mixed
852
864
mixed = np .array (
@@ -867,15 +879,23 @@ def test_startswith(self):
867
879
)
868
880
tm .assert_series_equal (rs , xp )
869
881
870
- def test_endswith (self ):
871
- values = Series (["om" , np .nan , "foo_nom" , "nom" , "bar_foo" , np .nan , "foo" ])
882
+ @pytest .mark .parametrize ("dtype" , [None , "category" ])
883
+ @pytest .mark .parametrize ("null_value" , [None , np .nan , pd .NA ])
884
+ @pytest .mark .parametrize ("na" , [True , False ])
885
+ def test_endswith (self , dtype , null_value , na ):
886
+ # add category dtype parametrizations for GH-36241
887
+ values = Series (
888
+ ["om" , null_value , "foo_nom" , "nom" , "bar_foo" , null_value , "foo" ],
889
+ dtype = dtype ,
890
+ )
872
891
873
892
result = values .str .endswith ("foo" )
874
893
exp = Series ([False , np .nan , False , False , True , np .nan , True ])
875
894
tm .assert_series_equal (result , exp )
876
895
877
- result = values .str .endswith ("foo" , na = False )
878
- tm .assert_series_equal (result , exp .fillna (False ).astype (bool ))
896
+ result = values .str .endswith ("foo" , na = na )
897
+ exp = Series ([False , na , False , False , True , na , True ])
898
+ tm .assert_series_equal (result , exp )
879
899
880
900
# mixed
881
901
mixed = np .array (
@@ -3552,6 +3572,10 @@ def test_string_array(any_string_method):
3552
3572
assert result .dtype == "boolean"
3553
3573
result = result .astype (object )
3554
3574
3575
+ elif expected .dtype == "bool" :
3576
+ assert result .dtype == "boolean"
3577
+ result = result .astype ("bool" )
3578
+
3555
3579
elif expected .dtype == "float" and expected .isna ().any ():
3556
3580
assert result .dtype == "Int64"
3557
3581
result = result .astype ("float" )
0 commit comments