1
+ import contextlib
1
2
from datetime import (
2
3
date ,
3
4
datetime ,
@@ -383,9 +384,7 @@ def test_setitem_mask_smallint_upcast(self):
383
384
with pytest .raises (TypeError , match = "Invalid value" ):
384
385
ser [mask ] = Series (alt )
385
386
386
- with tm .assert_produces_warning (
387
- FutureWarning , match = "item of incompatible dtype"
388
- ):
387
+ with pytest .raises (TypeError , match = "Invalid value" ):
389
388
ser .mask (mask , alt , inplace = True )
390
389
391
390
res = ser .where (~ mask , Series (alt ))
@@ -738,58 +737,66 @@ def _check_inplace(self, is_inplace, orig, arr, obj):
738
737
def test_int_key (self , obj , key , expected , warn , val , indexer_sli , is_inplace ):
739
738
if not isinstance (key , int ):
740
739
pytest .skip ("Not relevant for int key" )
740
+ if warn :
741
+ ctx = pytest .raises (TypeError , match = "Invalid value" )
742
+ else :
743
+ ctx = contextlib .nullcontext ()
741
744
742
- with pytest . raises ( TypeError , match = "Invalid value" ) :
745
+ with ctx :
743
746
self .check_indexer (obj , key , expected , val , indexer_sli , is_inplace )
744
747
745
748
if indexer_sli is tm .loc :
746
- with pytest . raises ( TypeError , match = "Invalid value" ) :
749
+ with ctx :
747
750
self .check_indexer (obj , key , expected , val , tm .at , is_inplace )
748
751
elif indexer_sli is tm .iloc :
749
- with pytest . raises ( TypeError , match = "Invalid value" ) :
752
+ with ctx :
750
753
self .check_indexer (obj , key , expected , val , tm .iat , is_inplace )
751
754
752
755
rng = range (key , key + 1 )
753
- with pytest . raises ( TypeError , match = "Invalid value" ) :
756
+ with ctx :
754
757
self .check_indexer (obj , rng , expected , val , indexer_sli , is_inplace )
755
758
756
759
if indexer_sli is not tm .loc :
757
760
# Note: no .loc because that handles slice edges differently
758
761
slc = slice (key , key + 1 )
759
- with pytest . raises ( TypeError , match = "Invalid value" ) :
762
+ with ctx :
760
763
self .check_indexer (obj , slc , expected , val , indexer_sli , is_inplace )
761
764
762
765
ilkey = [key ]
763
- with pytest . raises ( TypeError , match = "Invalid value" ) :
766
+ with ctx :
764
767
self .check_indexer (obj , ilkey , expected , val , indexer_sli , is_inplace )
765
768
766
769
indkey = np .array (ilkey )
767
- with pytest . raises ( TypeError , match = "Invalid value" ) :
770
+ with ctx :
768
771
self .check_indexer (obj , indkey , expected , val , indexer_sli , is_inplace )
769
772
770
773
genkey = (x for x in [key ])
771
- with pytest . raises ( TypeError , match = "Invalid value" ) :
774
+ with ctx :
772
775
self .check_indexer (obj , genkey , expected , val , indexer_sli , is_inplace )
773
776
774
777
def test_slice_key (self , obj , key , expected , warn , val , indexer_sli , is_inplace ):
775
778
if not isinstance (key , slice ):
776
779
pytest .skip ("Not relevant for slice key" )
780
+ if warn :
781
+ ctx = pytest .raises (TypeError , match = "Invalid value" )
782
+ else :
783
+ ctx = contextlib .nullcontext ()
777
784
778
785
if indexer_sli is not tm .loc :
779
786
# Note: no .loc because that handles slice edges differently
780
- with pytest . raises ( TypeError , match = "Invalid value" ) :
787
+ with ctx :
781
788
self .check_indexer (obj , key , expected , val , indexer_sli , is_inplace )
782
789
783
790
ilkey = list (range (len (obj )))[key ]
784
- with pytest . raises ( TypeError , match = "Invalid value" ) :
791
+ with ctx :
785
792
self .check_indexer (obj , ilkey , expected , val , indexer_sli , is_inplace )
786
793
787
794
indkey = np .array (ilkey )
788
- with pytest . raises ( TypeError , match = "Invalid value" ) :
795
+ with ctx :
789
796
self .check_indexer (obj , indkey , expected , val , indexer_sli , is_inplace )
790
797
791
798
genkey = (x for x in indkey )
792
- with pytest . raises ( TypeError , match = "Invalid value" ) :
799
+ with ctx :
793
800
self .check_indexer (obj , genkey , expected , val , indexer_sli , is_inplace )
794
801
795
802
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):
805
812
indexer_sli (obj )[mask ] = val
806
813
return
807
814
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 :
809
819
indexer_sli (obj )[mask ] = val
810
- tm .assert_series_equal (obj , expected )
811
820
812
821
def test_series_where (self , obj , key , expected , warn , val , is_inplace ):
813
822
mask = np .zeros (obj .shape , dtype = bool )
0 commit comments