@@ -273,25 +273,16 @@ def test_setitem_mask_align_and_promote(self):
273
273
mask = ts > 0
274
274
left = ts .copy ()
275
275
right = ts [mask ].copy ().map (str )
276
- with tm .assert_produces_warning (
277
- FutureWarning , match = "item of incompatible dtype"
278
- ):
276
+ with pytest .raises (TypeError , match = "Invalid value" ):
279
277
left [mask ] = right
280
- expected = ts .map (lambda t : str (t ) if t > 0 else t )
281
- tm .assert_series_equal (left , expected )
282
278
283
279
def test_setitem_mask_promote_strs (self ):
284
280
ser = Series ([0 , 1 , 2 , 0 ])
285
281
mask = ser > 0
286
282
ser2 = ser [mask ].map (str )
287
- with tm .assert_produces_warning (
288
- FutureWarning , match = "item of incompatible dtype"
289
- ):
283
+ with pytest .raises (TypeError , match = "Invalid value" ):
290
284
ser [mask ] = ser2
291
285
292
- expected = Series ([0 , "1" , "2" , 0 ])
293
- tm .assert_series_equal (ser , expected )
294
-
295
286
def test_setitem_mask_promote (self ):
296
287
ser = Series ([0 , "foo" , "bar" , 0 ])
297
288
mask = Series ([False , True , True , False ])
@@ -379,12 +370,8 @@ def test_setitem_with_bool_mask_and_values_matching_n_trues_in_length(self):
379
370
def test_setitem_nan_with_bool (self ):
380
371
# GH 13034
381
372
result = Series ([True , False , True ])
382
- with tm .assert_produces_warning (
383
- FutureWarning , match = "item of incompatible dtype"
384
- ):
373
+ with pytest .raises (TypeError , match = "Invalid value" ):
385
374
result [0 ] = np .nan
386
- expected = Series ([np .nan , False , True ], dtype = object )
387
- tm .assert_series_equal (result , expected )
388
375
389
376
def test_setitem_mask_smallint_upcast (self ):
390
377
orig = Series ([1 , 2 , 3 ], dtype = "int8" )
@@ -393,22 +380,16 @@ def test_setitem_mask_smallint_upcast(self):
393
380
mask = np .array ([True , False , True ])
394
381
395
382
ser = orig .copy ()
396
- with tm .assert_produces_warning (
397
- FutureWarning , match = "item of incompatible dtype"
398
- ):
383
+ with pytest .raises (TypeError , match = "Invalid value" ):
399
384
ser [mask ] = Series (alt )
400
- expected = Series ([999 , 2 , 1001 ])
401
- tm .assert_series_equal (ser , expected )
402
385
403
- ser2 = orig .copy ()
404
386
with tm .assert_produces_warning (
405
387
FutureWarning , match = "item of incompatible dtype"
406
388
):
407
- ser2 .mask (mask , alt , inplace = True )
408
- tm .assert_series_equal (ser2 , expected )
389
+ ser .mask (mask , alt , inplace = True )
409
390
410
- ser3 = orig . copy ( )
411
- res = ser3 . where ( ~ mask , Series ( alt ) )
391
+ res = ser . where ( ~ mask , Series ( alt ) )
392
+ expected = Series ([ 999 , 2 , 1001 ] )
412
393
tm .assert_series_equal (res , expected )
413
394
414
395
def test_setitem_mask_smallint_no_upcast (self ):
@@ -1651,10 +1632,8 @@ def test_32878_int_itemsize():
1651
1632
arr = np .arange (5 ).astype ("i4" )
1652
1633
ser = Series (arr )
1653
1634
val = np .int64 (np .iinfo (np .int64 ).max )
1654
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1635
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1655
1636
ser [0 ] = val
1656
- expected = Series ([val , 1 , 2 , 3 , 4 ], dtype = np .int64 )
1657
- tm .assert_series_equal (ser , expected )
1658
1637
1659
1638
1660
1639
def test_32878_complex_itemsize ():
@@ -1664,20 +1643,15 @@ def test_32878_complex_itemsize():
1664
1643
val = val .astype ("c16" )
1665
1644
1666
1645
# GH#32878 used to coerce val to inf+0.000000e+00j
1667
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1646
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1668
1647
ser [0 ] = val
1669
- assert ser [0 ] == val
1670
- expected = Series ([val , 1 , 2 , 3 , 4 ], dtype = "c16" )
1671
- tm .assert_series_equal (ser , expected )
1672
1648
1673
1649
1674
1650
def test_37692 (indexer_al ):
1675
1651
# GH#37692
1676
1652
ser = Series ([1 , 2 , 3 ], index = ["a" , "b" , "c" ])
1677
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1653
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1678
1654
indexer_al (ser )["b" ] = "test"
1679
- expected = Series ([1 , "test" , 3 ], index = ["a" , "b" , "c" ], dtype = object )
1680
- tm .assert_series_equal (ser , expected )
1681
1655
1682
1656
1683
1657
def test_setitem_bool_int_float_consistency (indexer_sli ):
@@ -1687,14 +1661,12 @@ def test_setitem_bool_int_float_consistency(indexer_sli):
1687
1661
# as the setitem can be done losslessly
1688
1662
for dtype in [np .float64 , np .int64 ]:
1689
1663
ser = Series (0 , index = range (3 ), dtype = dtype )
1690
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1664
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1691
1665
indexer_sli (ser )[0 ] = True
1692
- assert ser .dtype == object
1693
1666
1694
1667
ser = Series (0 , index = range (3 ), dtype = bool )
1695
- with tm . assert_produces_warning ( FutureWarning , match = "incompatible dtype " ):
1668
+ with pytest . raises ( TypeError , match = "Invalid value " ):
1696
1669
ser [0 ] = dtype (1 )
1697
- assert ser .dtype == object
1698
1670
1699
1671
# 1.0 can be held losslessly, so no casting
1700
1672
ser = Series (0 , index = range (3 ), dtype = np .int64 )
0 commit comments