@@ -94,7 +94,7 @@ def test_validate_index():
9494
9595def test_operators ():
9696 # For every operator, we test that it works for the required type
97- # combinations and raises TypeError otherwise
97+ # combinations and assert_raises TypeError otherwise
9898 binary_op_dtypes = {
9999 "__add__" : "numeric" ,
100100 "__and__" : "integer_or_boolean" ,
@@ -178,25 +178,25 @@ def _array_vals():
178178 # See the promotion table in NEP 47 or the array
179179 # API spec page on type promotion. Mixed kind
180180 # promotion is not defined.
181- if (x .dtype == uint64 and y .dtype in [int8 , int16 , int32 , int64 ]
182- or y .dtype == uint64 and x .dtype in [int8 , int16 , int32 , int64 ]
183- or x .dtype in _integer_dtypes and y .dtype not in _integer_dtypes
184- or y .dtype in _integer_dtypes and x .dtype not in _integer_dtypes
185- or x .dtype in _boolean_dtypes and y .dtype not in _boolean_dtypes
186- or y .dtype in _boolean_dtypes and x .dtype not in _boolean_dtypes
187- or x .dtype in _floating_dtypes and y .dtype not in _floating_dtypes
188- or y .dtype in _floating_dtypes and x .dtype not in _floating_dtypes
189- ):
190- assert_raises (TypeError , lambda : getattr (x , _op )(y ))
181+ if (op not in comparison_ops and
182+ (x .dtype == uint64 and y .dtype in [int8 , int16 , int32 , int64 ]
183+ or y .dtype == uint64 and x .dtype in [int8 , int16 , int32 , int64 ]
184+ or x .dtype in _integer_dtypes and y .dtype not in _integer_dtypes
185+ or y .dtype in _integer_dtypes and x .dtype not in _integer_dtypes
186+ or x .dtype in _boolean_dtypes and y .dtype not in _boolean_dtypes
187+ or y .dtype in _boolean_dtypes and x .dtype not in _boolean_dtypes
188+ or x .dtype in _floating_dtypes and y .dtype not in _floating_dtypes
189+ or y .dtype in _floating_dtypes and x .dtype not in _floating_dtypes
190+ )):
191+ assert_raises (TypeError , lambda : getattr (x , _op )(y ), _op )
191192 # Ensure in-place operators only promote to the same dtype as the left operand.
192193 elif (
193194 _op .startswith ("__i" )
194195 and result_type (x .dtype , y .dtype ) != x .dtype
195196 ):
196197 assert_raises (TypeError , lambda : getattr (x , _op )(y ), _op )
197198 # Ensure only those dtypes that are required for every operator are allowed.
198- elif (dtypes == "all" and (x .dtype in _boolean_dtypes and y .dtype in _boolean_dtypes
199- or x .dtype in _numeric_dtypes and y .dtype in _numeric_dtypes )
199+ elif (dtypes == "all"
200200 or (dtypes == "real numeric" and x .dtype in _real_numeric_dtypes and y .dtype in _real_numeric_dtypes )
201201 or (dtypes == "numeric" and x .dtype in _numeric_dtypes and y .dtype in _numeric_dtypes )
202202 or dtypes == "integer" and x .dtype in _integer_dtypes and y .dtype in _integer_dtypes
@@ -207,7 +207,7 @@ def _array_vals():
207207 ):
208208 getattr (x , _op )(y )
209209 else :
210- assert_raises (TypeError , lambda : getattr (x , _op )(y ), _op )
210+ assert_raises (TypeError , lambda : getattr (x , _op )(y ), ( x , _op , y ) )
211211
212212 unary_op_dtypes = {
213213 "__abs__" : "numeric" ,
0 commit comments