File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -1228,8 +1228,8 @@ def wrapper(left, right):
12281228 "{op}" .format (typ = type (left ).__name__ , op = str_rep ))
12291229
12301230 elif (is_extension_array_dtype (left ) or
1231- is_extension_array_dtype (right )):
1232- # TODO: should this include `not is_scalar(right)`?
1231+ ( is_extension_array_dtype (right ) and not is_scalar ( right ) )):
1232+ # GH#22378 disallow scalar to exclude e.g. "category", "Int64"
12331233 return dispatch_to_extension_op (op , left , right )
12341234
12351235 elif is_datetime64_dtype (left ) or is_datetime64tz_dtype (left ):
Original file line number Diff line number Diff line change @@ -73,6 +73,22 @@ def test_more_na_comparisons(self, dtype):
7373
7474class TestArithmetic (object ):
7575
76+ @pytest .mark .parametrize ("op" , [operator .add , ops .radd ])
77+ @pytest .mark .parametrize ("other" , ["category" , "Int64" ])
78+ def test_add_extension_scalar (self , other , box , op ):
79+ # GH#22378
80+ # Check that scalars satisfying is_extension_array_dtype(obj)
81+ # do not incorrectly try to dispatch to an ExtensionArray operation
82+
83+ arr = pd .Series (['a' , 'b' , 'c' ])
84+ expected = pd .Series ([op (x , other ) for x in arr ])
85+
86+ arr = tm .box_expected (arr , box )
87+ expected = tm .box_expected (expected , box )
88+
89+ result = op (arr , other )
90+ tm .assert_equal (result , expected )
91+
7692 @pytest .mark .parametrize ('box' , [
7793 pytest .param (pd .Index ,
7894 marks = pytest .mark .xfail (reason = "Does not mask nulls" ,
You can’t perform that action at this time.
0 commit comments