@@ -520,6 +520,7 @@ def test_where_axis_with_upcast(self):
520
520
result = df .where (mask , ser , axis = "columns" )
521
521
tm .assert_frame_equal (result , expected )
522
522
523
+ result = df .copy ()
523
524
with pytest .raises (TypeError , match = "Invalid value" ):
524
525
result .where (mask , ser , axis = "columns" , inplace = True )
525
526
@@ -573,15 +574,10 @@ def test_where_axis_multiple_dtypes(self):
573
574
result = df .where (mask , d1 , axis = "index" )
574
575
tm .assert_frame_equal (result , expected )
575
576
result = df .copy ()
576
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
577
- return_value = result .where (mask , d1 , inplace = True )
578
- assert return_value is None
579
- tm .assert_frame_equal (result , expected )
580
- result = df .copy ()
581
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
577
+ with pytest .raises (TypeError , match = "Invalid value" ):
578
+ result .where (mask , d1 , inplace = True )
579
+ with pytest .raises (TypeError , match = "Invalid value" ):
582
580
return_value = result .where (mask , d1 , inplace = True , axis = "index" )
583
- assert return_value is None
584
- tm .assert_frame_equal (result , expected )
585
581
586
582
d2 = df .copy ().drop (1 , axis = 1 )
587
583
expected = df .copy ()
@@ -728,11 +724,8 @@ def test_where_interval_fullop_downcast(self, frame_or_series):
728
724
res = obj .where (~ obj .notna (), other )
729
725
tm .assert_equal (res , other )
730
726
731
- with tm .assert_produces_warning (
732
- FutureWarning , match = "Setting an item of incompatible dtype"
733
- ):
727
+ with pytest .raises (TypeError , match = "Invalid value" ):
734
728
obj .mask (obj .notna (), other , inplace = True )
735
- tm .assert_equal (obj , other .astype (object ))
736
729
737
730
@pytest .mark .parametrize (
738
731
"dtype" ,
@@ -762,14 +755,10 @@ def test_where_datetimelike_noop(self, dtype):
762
755
763
756
res4 = df .mask (mask2 , "foo" )
764
757
tm .assert_frame_equal (res4 , df )
765
- expected = DataFrame (4 , index = df .index , columns = df .columns )
766
758
767
759
# unlike where, Block.putmask does not downcast
768
- with tm .assert_produces_warning (
769
- FutureWarning , match = "Setting an item of incompatible dtype"
770
- ):
760
+ with pytest .raises (TypeError , match = "Invalid value" ):
771
761
df .mask (~ mask2 , 4 , inplace = True )
772
- tm .assert_frame_equal (df , expected .astype (object ))
773
762
774
763
775
764
def test_where_int_downcasting_deprecated ():
@@ -923,11 +912,8 @@ def test_where_period_invalid_na(frame_or_series, as_cat, request):
923
912
result = obj .mask (mask , tdnat )
924
913
tm .assert_equal (result , expected )
925
914
926
- with tm .assert_produces_warning (
927
- FutureWarning , match = "Setting an item of incompatible dtype"
928
- ):
915
+ with pytest .raises (TypeError , match = "Invalid value" ):
929
916
obj .mask (mask , tdnat , inplace = True )
930
- tm .assert_equal (obj , expected )
931
917
932
918
933
919
def test_where_nullable_invalid_na (frame_or_series , any_numeric_ea_dtype ):
@@ -1009,9 +995,7 @@ def test_where_dt64_2d():
1009
995
"B" : dta [:, 1 ],
1010
996
}
1011
997
)
1012
- with tm .assert_produces_warning (
1013
- FutureWarning , match = "Setting an item of incompatible dtype"
1014
- ):
998
+ with pytest .raises (TypeError , match = "Invalid value" ):
1015
999
_check_where_equivalences (df , mask , other , expected )
1016
1000
1017
1001
# setting nothing in either column
0 commit comments