@@ -564,6 +564,8 @@ def test_df_div_zero_series_does_not_commute(self):
564564 res2 = df / ser
565565 assert not res .fillna (0 ).equals (res2 .fillna (0 ))
566566
567+
568+
567569 # ------------------------------------------------------------------
568570 # Mod By Zero
569571
@@ -855,6 +857,35 @@ def test_modulo_zero_int(self):
855857 result = 0 % s
856858 expected = Series ([np .nan , 0.0 ])
857859 tm .assert_series_equal (result , expected )
860+
861+ def test_np_array_mul_ea_array_returns_extensionarray ():
862+ np_array = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = tm .SIGNED_INT_NUMPY_DTYPES [0 ])
863+ ea_array = pd .array ([1 , 2 , 3 , 4 , 5 ], dtype = tm .SIGNED_INT_EA_DTYPES [0 ])
864+ result = np_array * ea_array
865+ tm .assert_isinstance (result , type (ea_array ))
866+ tm .assert_equal (result , pd .array ([1 , 4 , 9 , 16 , 25 ], dtype = tm .SIGNED_INT_EA_DTYPES [0 ]))
867+ tm .assert_equal (result , pd .array ([1 , 4 , 9 , 16 , 25 ], dtype = tm .SIGNED_INT_EA_DTYPES [0 ]))
868+
869+ def test_df_mul_np_and_ea_array_shape_and_errors ():
870+ df = pd .DataFrame (np .arange (50 ).reshape (10 , 5 )).notna ().values
871+ NP_array = pd .array ([i for i in range (10 )], dtype = tm .SIGNED_INT_NUMPY_DTYPES [0 ]).reshape (10 , 1 )
872+ EA_array = pd .array ([i for i in range (10 )], dtype = tm .SIGNED_INT_EA_DTYPES [0 ]).reshape (10 , 1 )
873+
874+ result_np = df * NP_array
875+ tm .assert_isinstance (result_np , np .ndarray )
876+ tm .assert_equal (result_np .shape , (10 , 5 ))
877+
878+ with tm .assert_raises (TypeError ):
879+ _ = df * EA_array
880+
881+ def test_non_1d_ea_raises_typeerror ():
882+ ea_array = pd .array ([1 , 2 , 3 , 4 , 5 ], dtype = tm .SIGNED_INT_EA_DTYPES [0 ]).reshape (5 , 1 )
883+ np_array = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = tm .SIGNED_INT_NUMPY_DTYPES [0 ]).reshape (5 , 1 )
884+
885+ with tm .assert_raises (TypeError ):
886+ _ = ea_array * np_array
887+ with tm .assert_raises (TypeError ):
888+ _ = np_array * ea_array
858889
859890
860891class TestAdditionSubtraction :
0 commit comments