Skip to content

Commit 4e3bb2b

Browse files
committed
wip
1 parent bea24ca commit 4e3bb2b

File tree

2 files changed

+13
-46
lines changed

2 files changed

+13
-46
lines changed

pandas/tests/indexing/multiindex/test_setitem.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,8 @@ def test_multiindex_assignment_single_dtype(self):
213213
tm.assert_series_equal(result, exp)
214214

215215
# arr + 0.5 cannot be cast losslessly to int, so we upcast
216-
with tm.assert_produces_warning(
217-
FutureWarning, match="item of incompatible dtype"
218-
):
216+
with pytest.raises(TypeError, match="Invalid value"):
219217
df.loc[4, "c"] = arr + 0.5
220-
result = df.loc[4, "c"]
221-
exp = exp + 0.5
222-
tm.assert_series_equal(result, exp)
223218

224219
# scalar ok
225220
df.loc[4, "c"] = 10

pandas/tests/series/indexing/test_setitem.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,16 @@ def test_setitem_mask_align_and_promote(self):
273273
mask = ts > 0
274274
left = ts.copy()
275275
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"):
279277
left[mask] = right
280-
expected = ts.map(lambda t: str(t) if t > 0 else t)
281-
tm.assert_series_equal(left, expected)
282278

283279
def test_setitem_mask_promote_strs(self):
284280
ser = Series([0, 1, 2, 0])
285281
mask = ser > 0
286282
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"):
290284
ser[mask] = ser2
291285

292-
expected = Series([0, "1", "2", 0])
293-
tm.assert_series_equal(ser, expected)
294-
295286
def test_setitem_mask_promote(self):
296287
ser = Series([0, "foo", "bar", 0])
297288
mask = Series([False, True, True, False])
@@ -379,12 +370,8 @@ def test_setitem_with_bool_mask_and_values_matching_n_trues_in_length(self):
379370
def test_setitem_nan_with_bool(self):
380371
# GH 13034
381372
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"):
385374
result[0] = np.nan
386-
expected = Series([np.nan, False, True], dtype=object)
387-
tm.assert_series_equal(result, expected)
388375

389376
def test_setitem_mask_smallint_upcast(self):
390377
orig = Series([1, 2, 3], dtype="int8")
@@ -393,22 +380,16 @@ def test_setitem_mask_smallint_upcast(self):
393380
mask = np.array([True, False, True])
394381

395382
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"):
399384
ser[mask] = Series(alt)
400-
expected = Series([999, 2, 1001])
401-
tm.assert_series_equal(ser, expected)
402385

403-
ser2 = orig.copy()
404386
with tm.assert_produces_warning(
405387
FutureWarning, match="item of incompatible dtype"
406388
):
407-
ser2.mask(mask, alt, inplace=True)
408-
tm.assert_series_equal(ser2, expected)
389+
ser.mask(mask, alt, inplace=True)
409390

410-
ser3 = orig.copy()
411-
res = ser3.where(~mask, Series(alt))
391+
res = ser.where(~mask, Series(alt))
392+
expected = Series([999, 2, 1001])
412393
tm.assert_series_equal(res, expected)
413394

414395
def test_setitem_mask_smallint_no_upcast(self):
@@ -1651,10 +1632,8 @@ def test_32878_int_itemsize():
16511632
arr = np.arange(5).astype("i4")
16521633
ser = Series(arr)
16531634
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"):
16551636
ser[0] = val
1656-
expected = Series([val, 1, 2, 3, 4], dtype=np.int64)
1657-
tm.assert_series_equal(ser, expected)
16581637

16591638

16601639
def test_32878_complex_itemsize():
@@ -1664,20 +1643,15 @@ def test_32878_complex_itemsize():
16641643
val = val.astype("c16")
16651644

16661645
# 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"):
16681647
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)
16721648

16731649

16741650
def test_37692(indexer_al):
16751651
# GH#37692
16761652
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"):
16781654
indexer_al(ser)["b"] = "test"
1679-
expected = Series([1, "test", 3], index=["a", "b", "c"], dtype=object)
1680-
tm.assert_series_equal(ser, expected)
16811655

16821656

16831657
def test_setitem_bool_int_float_consistency(indexer_sli):
@@ -1687,14 +1661,12 @@ def test_setitem_bool_int_float_consistency(indexer_sli):
16871661
# as the setitem can be done losslessly
16881662
for dtype in [np.float64, np.int64]:
16891663
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"):
16911665
indexer_sli(ser)[0] = True
1692-
assert ser.dtype == object
16931666

16941667
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"):
16961669
ser[0] = dtype(1)
1697-
assert ser.dtype == object
16981670

16991671
# 1.0 can be held losslessly, so no casting
17001672
ser = Series(0, index=range(3), dtype=np.int64)

0 commit comments

Comments
 (0)