@@ -764,8 +764,7 @@ def check_promotion_cases(self, promote_func):
764
764
assert_equal (promote_func (b , u8 ), np .dtype (np .uint8 ))
765
765
assert_equal (promote_func (i8 , u8 ), np .dtype (np .int16 ))
766
766
assert_equal (promote_func (u8 , i32 ), np .dtype (np .int32 ))
767
- assert_equal (promote_func (i32 , f32 ), np .dtype (np .float64 ))
768
- assert_equal (promote_func (i64 , f32 ), np .dtype (np .float64 ))
767
+
769
768
assert_equal (promote_func (f32 , i16 ), np .dtype (np .float32 ))
770
769
assert_equal (promote_func (f32 , c64 ), np .dtype (np .complex64 ))
771
770
assert_equal (promote_func (c128 , f32 ), np .dtype (np .complex128 ))
@@ -774,8 +773,6 @@ def check_promotion_cases(self, promote_func):
774
773
assert_equal (promote_func (np .array ([b ]), i8 ), np .dtype (np .int8 ))
775
774
assert_equal (promote_func (np .array ([b ]), u8 ), np .dtype (np .uint8 ))
776
775
assert_equal (promote_func (np .array ([b ]), i32 ), np .dtype (np .int32 ))
777
- assert_equal (promote_func (np .array ([i8 ]), i64 ), np .dtype (np .int8 ))
778
- assert_equal (promote_func (f64 , np .array ([f32 ])), np .dtype (np .float32 ))
779
776
assert_equal (promote_func (c64 , np .array ([f64 ])),
780
777
np .dtype (np .complex128 ))
781
778
assert_equal (promote_func (np .complex64 (3j ), np .array ([f64 ])),
@@ -787,6 +784,22 @@ def check_promotion_cases(self, promote_func):
787
784
assert_equal (promote_func (np .array ([b ]), i64 ), np .dtype (np .int64 ))
788
785
assert_equal (promote_func (np .array ([i8 ]), f64 ), np .dtype (np .float64 ))
789
786
787
+ def check_promotion_cases_2 (self , promote_func ):
788
+ # these are failing because of the "scalars do not upcast arrays" rule
789
+ # Two first tests (i32 + f32 -> f64, and i64+f32 -> f64) xfail
790
+ # until ufuncs implement the proper type promotion (ufunc loops?)
791
+ b = np .bool_ (0 )
792
+ i8 , i16 , i32 , i64 = np .int8 (0 ), np .int16 (0 ), np .int32 (0 ), np .int64 (0 )
793
+ u8 = np .uint8 (0 )
794
+ f32 , f64 = np .float32 (0 ), np .float64 (0 )
795
+ c64 , c128 = np .complex64 (0 ), np .complex128 (0 )
796
+
797
+ assert_equal (promote_func (i32 , f32 ), np .dtype (np .float64 ))
798
+ assert_equal (promote_func (i64 , f32 ), np .dtype (np .float64 ))
799
+
800
+ assert_equal (promote_func (np .array ([i8 ]), i64 ), np .dtype (np .int8 ))
801
+ assert_equal (promote_func (f64 , np .array ([f32 ])), np .dtype (np .float32 ))
802
+
790
803
# float and complex are treated as the same "kind" for
791
804
# the purposes of array-scalar promotion, so that you can do
792
805
# (0j + float32array) to get a complex64 array instead of
@@ -842,6 +855,13 @@ def res_type(a, b):
842
855
# assert_equal(b, [0.0, 1.5])
843
856
# assert_equal(b.dtype, np.dtype('f4'))
844
857
858
+ @pytest .mark .xfail (reason = "'Scalars do not upcast arrays' rule" )
859
+ def test_coercion_2 (self ):
860
+ def res_type (a , b ):
861
+ return np .add (a , b ).dtype
862
+
863
+ self .check_promotion_cases_2 (res_type )
864
+
845
865
def test_result_type (self ):
846
866
self .check_promotion_cases (np .result_type )
847
867
0 commit comments