@@ -349,7 +349,8 @@ def test_take(self, indices):
349
349
350
350
if not isinstance (indices , (DatetimeIndex , PeriodIndex , TimedeltaIndex )):
351
351
# GH 10791
352
- with pytest .raises (AttributeError ):
352
+ msg = r"'(.*Index)' object has no attribute 'freq'"
353
+ with pytest .raises (AttributeError , match = msg ):
353
354
indices .freq
354
355
355
356
def test_take_invalid_kwargs (self ):
@@ -537,9 +538,10 @@ def test_delete_base(self, indices):
537
538
assert result .equals (expected )
538
539
assert result .name == expected .name
539
540
540
- with pytest .raises ((IndexError , ValueError )):
541
- # either depending on numpy version
542
- indices .delete (len (indices ))
541
+ length = len (indices )
542
+ msg = f"index { length } is out of bounds for axis 0 with size { length } "
543
+ with pytest .raises (IndexError , match = msg ):
544
+ indices .delete (length )
543
545
544
546
def test_equals (self , indices ):
545
547
if isinstance (indices , IntervalIndex ):
@@ -787,13 +789,14 @@ def test_putmask_with_wrong_mask(self):
787
789
# GH18368
788
790
index = self .create_index ()
789
791
790
- with pytest .raises (ValueError ):
792
+ msg = "putmask: mask and data must be the same size"
793
+ with pytest .raises (ValueError , match = msg ):
791
794
index .putmask (np .ones (len (index ) + 1 , np .bool ), 1 )
792
795
793
- with pytest .raises (ValueError ):
796
+ with pytest .raises (ValueError , match = msg ):
794
797
index .putmask (np .ones (len (index ) - 1 , np .bool ), 1 )
795
798
796
- with pytest .raises (ValueError ):
799
+ with pytest .raises (ValueError , match = msg ):
797
800
index .putmask ("foo" , 1 )
798
801
799
802
@pytest .mark .parametrize ("copy" , [True , False ])
@@ -861,10 +864,21 @@ def test_getitem_2d_deprecated(self):
861
864
862
865
def test_contains_requires_hashable_raises (self ):
863
866
idx = self .create_index ()
864
- with pytest .raises (TypeError , match = "unhashable type" ):
867
+
868
+ msg = "unhashable type: 'list'"
869
+ with pytest .raises (TypeError , match = msg ):
865
870
[] in idx
866
871
867
- with pytest .raises (TypeError ):
872
+ msg = "|" .join (
873
+ [
874
+ r"unhashable type: 'dict'" ,
875
+ r"must be real number, not dict" ,
876
+ r"an integer is required" ,
877
+ r"\{\}" ,
878
+ r"pandas\._libs\.interval\.IntervalTree' is not iterable" ,
879
+ ]
880
+ )
881
+ with pytest .raises (TypeError , match = msg ):
868
882
{} in idx ._engine
869
883
870
884
def test_copy_copies_cache (self ):
0 commit comments