Skip to content

Commit 570ab12

Browse files
committed
wip
1 parent 4e3bb2b commit 570ab12

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

pandas/tests/series/indexing/test_setitem.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from datetime import (
23
date,
34
datetime,
@@ -383,9 +384,7 @@ def test_setitem_mask_smallint_upcast(self):
383384
with pytest.raises(TypeError, match="Invalid value"):
384385
ser[mask] = Series(alt)
385386

386-
with tm.assert_produces_warning(
387-
FutureWarning, match="item of incompatible dtype"
388-
):
387+
with pytest.raises(TypeError, match="Invalid value"):
389388
ser.mask(mask, alt, inplace=True)
390389

391390
res = ser.where(~mask, Series(alt))
@@ -738,58 +737,66 @@ def _check_inplace(self, is_inplace, orig, arr, obj):
738737
def test_int_key(self, obj, key, expected, warn, val, indexer_sli, is_inplace):
739738
if not isinstance(key, int):
740739
pytest.skip("Not relevant for int key")
740+
if warn:
741+
ctx = pytest.raises(TypeError, match="Invalid value")
742+
else:
743+
ctx = contextlib.nullcontext()
741744

742-
with pytest.raises(TypeError, match="Invalid value"):
745+
with ctx:
743746
self.check_indexer(obj, key, expected, val, indexer_sli, is_inplace)
744747

745748
if indexer_sli is tm.loc:
746-
with pytest.raises(TypeError, match="Invalid value"):
749+
with ctx:
747750
self.check_indexer(obj, key, expected, val, tm.at, is_inplace)
748751
elif indexer_sli is tm.iloc:
749-
with pytest.raises(TypeError, match="Invalid value"):
752+
with ctx:
750753
self.check_indexer(obj, key, expected, val, tm.iat, is_inplace)
751754

752755
rng = range(key, key + 1)
753-
with pytest.raises(TypeError, match="Invalid value"):
756+
with ctx:
754757
self.check_indexer(obj, rng, expected, val, indexer_sli, is_inplace)
755758

756759
if indexer_sli is not tm.loc:
757760
# Note: no .loc because that handles slice edges differently
758761
slc = slice(key, key + 1)
759-
with pytest.raises(TypeError, match="Invalid value"):
762+
with ctx:
760763
self.check_indexer(obj, slc, expected, val, indexer_sli, is_inplace)
761764

762765
ilkey = [key]
763-
with pytest.raises(TypeError, match="Invalid value"):
766+
with ctx:
764767
self.check_indexer(obj, ilkey, expected, val, indexer_sli, is_inplace)
765768

766769
indkey = np.array(ilkey)
767-
with pytest.raises(TypeError, match="Invalid value"):
770+
with ctx:
768771
self.check_indexer(obj, indkey, expected, val, indexer_sli, is_inplace)
769772

770773
genkey = (x for x in [key])
771-
with pytest.raises(TypeError, match="Invalid value"):
774+
with ctx:
772775
self.check_indexer(obj, genkey, expected, val, indexer_sli, is_inplace)
773776

774777
def test_slice_key(self, obj, key, expected, warn, val, indexer_sli, is_inplace):
775778
if not isinstance(key, slice):
776779
pytest.skip("Not relevant for slice key")
780+
if warn:
781+
ctx = pytest.raises(TypeError, match="Invalid value")
782+
else:
783+
ctx = contextlib.nullcontext()
777784

778785
if indexer_sli is not tm.loc:
779786
# Note: no .loc because that handles slice edges differently
780-
with pytest.raises(TypeError, match="Invalid value"):
787+
with ctx:
781788
self.check_indexer(obj, key, expected, val, indexer_sli, is_inplace)
782789

783790
ilkey = list(range(len(obj)))[key]
784-
with pytest.raises(TypeError, match="Invalid value"):
791+
with ctx:
785792
self.check_indexer(obj, ilkey, expected, val, indexer_sli, is_inplace)
786793

787794
indkey = np.array(ilkey)
788-
with pytest.raises(TypeError, match="Invalid value"):
795+
with ctx:
789796
self.check_indexer(obj, indkey, expected, val, indexer_sli, is_inplace)
790797

791798
genkey = (x for x in indkey)
792-
with pytest.raises(TypeError, match="Invalid value"):
799+
with ctx:
793800
self.check_indexer(obj, genkey, expected, val, indexer_sli, is_inplace)
794801

795802
def test_mask_key(self, obj, key, expected, warn, val, indexer_sli):
@@ -805,9 +812,11 @@ def test_mask_key(self, obj, key, expected, warn, val, indexer_sli):
805812
indexer_sli(obj)[mask] = val
806813
return
807814

808-
with pytest.raises(TypeError, match="Invalid value"):
815+
if warn:
816+
with pytest.raises(TypeError, match="Invalid value"):
817+
indexer_sli(obj)[mask] = val
818+
else:
809819
indexer_sli(obj)[mask] = val
810-
tm.assert_series_equal(obj, expected)
811820

812821
def test_series_where(self, obj, key, expected, warn, val, is_inplace):
813822
mask = np.zeros(obj.shape, dtype=bool)

0 commit comments

Comments
 (0)