@@ -596,11 +596,14 @@ def test_setitem_enlarge_with_na(
596
596
):
597
597
# GH#32346
598
598
ser = Series ([1 , 2 ], dtype = dtype )
599
- with tm .assert_produces_warning (warn , match = "incompatible dtype" ):
599
+ if warn :
600
+ with pytest .raises (TypeError , match = "Invalid value" ):
601
+ ser [indexer ] = na
602
+ else :
600
603
ser [indexer ] = na
601
- expected_values = [1 , target_na ] if indexer == 1 else [1 , 2 , target_na ]
602
- expected = Series (expected_values , dtype = target_dtype )
603
- tm .assert_series_equal (ser , expected )
604
+ expected_values = [1 , target_na ] if indexer == 1 else [1 , 2 , target_na ]
605
+ expected = Series (expected_values , dtype = target_dtype )
606
+ tm .assert_series_equal (ser , expected )
604
607
605
608
def test_setitem_enlargement_object_none (self , nulls_fixture , using_infer_string ):
606
609
# GH#48665
@@ -694,14 +697,8 @@ def test_setitem_non_bool_into_bool(self, val, indexer_sli, unique):
694
697
if not unique :
695
698
ser .index = [1 , 1 ]
696
699
697
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
700
+ with pytest . raises ( TypeError , match = "Invalid value " ):
698
701
indexer_sli (ser )[1 ] = val
699
- assert type (ser .iloc [1 ]) == type (val )
700
-
701
- expected = Series ([True , val ], dtype = object , index = ser .index )
702
- if not unique and indexer_sli is not tm .iloc :
703
- expected = Series ([val , val ], dtype = object , index = [1 , 1 ])
704
- tm .assert_series_equal (ser , expected )
705
702
706
703
def test_setitem_boolean_array_into_npbool (self ):
707
704
# GH#45462
@@ -712,10 +709,8 @@ def test_setitem_boolean_array_into_npbool(self):
712
709
ser [:2 ] = arr [:2 ] # no NAs -> can set inplace
713
710
assert ser ._values is values
714
711
715
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
712
+ with pytest . raises ( TypeError , match = "Invalid value " ):
716
713
ser [1 :] = arr [1 :] # has an NA -> cast to boolean dtype
717
- expected = Series (arr )
718
- tm .assert_series_equal (ser , expected )
719
714
720
715
721
716
class SetitemCastingEquivalents :
@@ -763,36 +758,36 @@ def test_int_key(self, obj, key, expected, warn, val, indexer_sli, is_inplace):
763
758
if not isinstance (key , int ):
764
759
pytest .skip ("Not relevant for int key" )
765
760
766
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
761
+ with pytest . raises ( TypeError , match = "Invalid value " ):
767
762
self .check_indexer (obj , key , expected , val , indexer_sli , is_inplace )
768
763
769
764
if indexer_sli is tm .loc :
770
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
765
+ with pytest . raises ( TypeError , match = "Invalid value " ):
771
766
self .check_indexer (obj , key , expected , val , tm .at , is_inplace )
772
767
elif indexer_sli is tm .iloc :
773
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
768
+ with pytest . raises ( TypeError , match = "Invalid value " ):
774
769
self .check_indexer (obj , key , expected , val , tm .iat , is_inplace )
775
770
776
771
rng = range (key , key + 1 )
777
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
772
+ with pytest . raises ( TypeError , match = "Invalid value " ):
778
773
self .check_indexer (obj , rng , expected , val , indexer_sli , is_inplace )
779
774
780
775
if indexer_sli is not tm .loc :
781
776
# Note: no .loc because that handles slice edges differently
782
777
slc = slice (key , key + 1 )
783
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
778
+ with pytest . raises ( TypeError , match = "Invalid value " ):
784
779
self .check_indexer (obj , slc , expected , val , indexer_sli , is_inplace )
785
780
786
781
ilkey = [key ]
787
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
782
+ with pytest . raises ( TypeError , match = "Invalid value " ):
788
783
self .check_indexer (obj , ilkey , expected , val , indexer_sli , is_inplace )
789
784
790
785
indkey = np .array (ilkey )
791
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
786
+ with pytest . raises ( TypeError , match = "Invalid value " ):
792
787
self .check_indexer (obj , indkey , expected , val , indexer_sli , is_inplace )
793
788
794
789
genkey = (x for x in [key ])
795
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
790
+ with pytest . raises ( TypeError , match = "Invalid value " ):
796
791
self .check_indexer (obj , genkey , expected , val , indexer_sli , is_inplace )
797
792
798
793
def test_slice_key (self , obj , key , expected , warn , val , indexer_sli , is_inplace ):
@@ -801,19 +796,19 @@ def test_slice_key(self, obj, key, expected, warn, val, indexer_sli, is_inplace)
801
796
802
797
if indexer_sli is not tm .loc :
803
798
# Note: no .loc because that handles slice edges differently
804
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
799
+ with pytest . raises ( TypeError , match = "Invalid value " ):
805
800
self .check_indexer (obj , key , expected , val , indexer_sli , is_inplace )
806
801
807
802
ilkey = list (range (len (obj )))[key ]
808
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
803
+ with pytest . raises ( TypeError , match = "Invalid value " ):
809
804
self .check_indexer (obj , ilkey , expected , val , indexer_sli , is_inplace )
810
805
811
806
indkey = np .array (ilkey )
812
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
807
+ with pytest . raises ( TypeError , match = "Invalid value " ):
813
808
self .check_indexer (obj , indkey , expected , val , indexer_sli , is_inplace )
814
809
815
810
genkey = (x for x in indkey )
816
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
811
+ with pytest . raises ( TypeError , match = "Invalid value " ):
817
812
self .check_indexer (obj , genkey , expected , val , indexer_sli , is_inplace )
818
813
819
814
def test_mask_key (self , obj , key , expected , warn , val , indexer_sli ):
@@ -829,7 +824,7 @@ def test_mask_key(self, obj, key, expected, warn, val, indexer_sli):
829
824
indexer_sli (obj )[mask ] = val
830
825
return
831
826
832
- with tm . assert_produces_warning ( warn , match = "incompatible dtype " ):
827
+ with pytest . raises ( TypeError , match = "Invalid value " ):
833
828
indexer_sli (obj )[mask ] = val
834
829
tm .assert_series_equal (obj , expected )
835
830
@@ -1185,11 +1180,8 @@ def test_setitem_example(self):
1185
1180
obj = Series (idx )
1186
1181
val = Interval (0.5 , 1.5 )
1187
1182
1188
- with tm .assert_produces_warning (
1189
- FutureWarning , match = "Setting an item of incompatible dtype"
1190
- ):
1183
+ with pytest .raises (TypeError , match = "Invalid value" ):
1191
1184
obj [0 ] = val
1192
- assert obj .dtype == "Interval[float64, right]"
1193
1185
1194
1186
@pytest .fixture
1195
1187
def obj (self ):
@@ -1583,55 +1575,37 @@ def test_20643():
1583
1575
# closed by GH#45121
1584
1576
orig = Series ([0 , 1 , 2 ], index = ["a" , "b" , "c" ])
1585
1577
1586
- expected = Series ([0 , 2.7 , 2 ], index = ["a" , "b" , "c" ])
1587
-
1588
1578
ser = orig .copy ()
1589
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1579
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1590
1580
ser .at ["b" ] = 2.7
1591
- tm .assert_series_equal (ser , expected )
1592
1581
1593
- ser = orig .copy ()
1594
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1582
+ with pytest .raises (TypeError , match = "Invalid value" ):
1595
1583
ser .loc ["b" ] = 2.7
1596
- tm .assert_series_equal (ser , expected )
1597
1584
1598
- ser = orig .copy ()
1599
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1585
+ with pytest .raises (TypeError , match = "Invalid value" ):
1600
1586
ser ["b" ] = 2.7
1601
- tm .assert_series_equal (ser , expected )
1602
1587
1603
1588
ser = orig .copy ()
1604
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1589
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1605
1590
ser .iat [1 ] = 2.7
1606
- tm .assert_series_equal (ser , expected )
1607
1591
1608
- ser = orig .copy ()
1609
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1592
+ with pytest .raises (TypeError , match = "Invalid value" ):
1610
1593
ser .iloc [1 ] = 2.7
1611
- tm .assert_series_equal (ser , expected )
1612
1594
1613
1595
orig_df = orig .to_frame ("A" )
1614
- expected_df = expected .to_frame ("A" )
1615
1596
1616
1597
df = orig_df .copy ()
1617
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1598
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1618
1599
df .at ["b" , "A" ] = 2.7
1619
- tm .assert_frame_equal (df , expected_df )
1620
1600
1621
- df = orig_df .copy ()
1622
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1601
+ with pytest .raises (TypeError , match = "Invalid value" ):
1623
1602
df .loc ["b" , "A" ] = 2.7
1624
- tm .assert_frame_equal (df , expected_df )
1625
1603
1626
- df = orig_df .copy ()
1627
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1604
+ with pytest .raises (TypeError , match = "Invalid value" ):
1628
1605
df .iloc [1 , 0 ] = 2.7
1629
- tm .assert_frame_equal (df , expected_df )
1630
1606
1631
- df = orig_df .copy ()
1632
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1607
+ with pytest .raises (TypeError , match = "Invalid value" ):
1633
1608
df .iat [1 , 0 ] = 2.7
1634
- tm .assert_frame_equal (df , expected_df )
1635
1609
1636
1610
1637
1611
def test_20643_comment ():
@@ -1653,35 +1627,23 @@ def test_15413():
1653
1627
# fixed by GH#45121
1654
1628
ser = Series ([1 , 2 , 3 ])
1655
1629
1656
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1630
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1657
1631
ser [ser == 2 ] += 0.5
1658
- expected = Series ([1 , 2.5 , 3 ])
1659
- tm .assert_series_equal (ser , expected )
1660
1632
1661
- ser = Series ([1 , 2 , 3 ])
1662
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1633
+ with pytest .raises (TypeError , match = "Invalid value" ):
1663
1634
ser [1 ] += 0.5
1664
- tm .assert_series_equal (ser , expected )
1665
1635
1666
- ser = Series ([1 , 2 , 3 ])
1667
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1636
+ with pytest .raises (TypeError , match = "Invalid value" ):
1668
1637
ser .loc [1 ] += 0.5
1669
- tm .assert_series_equal (ser , expected )
1670
1638
1671
- ser = Series ([1 , 2 , 3 ])
1672
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1639
+ with pytest .raises (TypeError , match = "Invalid value" ):
1673
1640
ser .iloc [1 ] += 0.5
1674
- tm .assert_series_equal (ser , expected )
1675
1641
1676
- ser = Series ([1 , 2 , 3 ])
1677
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1642
+ with pytest .raises (TypeError , match = "Invalid value" ):
1678
1643
ser .iat [1 ] += 0.5
1679
- tm .assert_series_equal (ser , expected )
1680
1644
1681
- ser = Series ([1 , 2 , 3 ])
1682
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
1645
+ with pytest .raises (TypeError , match = "Invalid value" ):
1683
1646
ser .at [1 ] += 0.5
1684
- tm .assert_series_equal (ser , expected )
1685
1647
1686
1648
1687
1649
def test_32878_int_itemsize ():
0 commit comments