File tree 2 files changed +18
-2
lines changed
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):
1228
1228
"{op}" .format (typ = type (left ).__name__ , op = str_rep ))
1229
1229
1230
1230
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"
1233
1233
return dispatch_to_extension_op (op , left , right )
1234
1234
1235
1235
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):
73
73
74
74
class TestArithmetic (object ):
75
75
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
+
76
92
@pytest .mark .parametrize ('box' , [
77
93
pytest .param (pd .Index ,
78
94
marks = pytest .mark .xfail (reason = "Does not mask nulls" ,
You can’t perform that action at this time.
0 commit comments