@@ -330,26 +330,37 @@ def test_error(self, data, all_arithmetic_operators):
330
330
opa = getattr (data , op )
331
331
332
332
# invalid scalars
333
- with pytest .raises (TypeError ):
333
+ msg = (
334
+ r"(:?can only perform ops with numeric values)"
335
+ r"|(:?IntegerArray cannot perform the operation mod)"
336
+ )
337
+ with pytest .raises (TypeError , match = msg ):
334
338
ops ("foo" )
335
- with pytest .raises (TypeError ):
339
+ with pytest .raises (TypeError , match = msg ):
336
340
ops (pd .Timestamp ("20180101" ))
337
341
338
342
# invalid array-likes
339
- with pytest .raises (TypeError ):
343
+ with pytest .raises (TypeError , match = msg ):
340
344
ops (pd .Series ("foo" , index = s .index ))
341
345
342
346
if op != "__rpow__" :
343
347
# TODO(extension)
344
348
# rpow with a datetimelike coerces the integer array incorrectly
345
- with pytest .raises (TypeError ):
349
+ msg = (
350
+ r"(:?can only perform ops with numeric values)"
351
+ r"|(:?cannot perform .* with this index type: DatetimeArray)"
352
+ r"|(:?Addition/subtraction of integers and integer-arrays"
353
+ r" with DatetimeArray is no longer supported. *)"
354
+ )
355
+ with pytest .raises (TypeError , match = msg ):
346
356
ops (pd .Series (pd .date_range ("20180101" , periods = len (s ))))
347
357
348
358
# 2d
349
359
result = opa (pd .DataFrame ({"A" : s }))
350
360
assert result is NotImplemented
351
361
352
- with pytest .raises (NotImplementedError ):
362
+ msg = r"can only perform ops with 1-d structures"
363
+ with pytest .raises (NotImplementedError , match = msg ):
353
364
opa (np .arange (len (s )).reshape (- 1 , len (s )))
354
365
355
366
@pytest .mark .parametrize ("zero, negative" , [(0 , False ), (0.0 , False ), (- 0.0 , True )])
@@ -589,7 +600,8 @@ def test_astype(self, all_data):
589
600
590
601
# coerce to same numpy_dtype - mixed
591
602
s = pd .Series (mixed )
592
- with pytest .raises (ValueError ):
603
+ msg = r"cannot convert to .*-dtype NumPy array with missing values.*"
604
+ with pytest .raises (ValueError , match = msg ):
593
605
s .astype (all_data .dtype .numpy_dtype )
594
606
595
607
# coerce to object
@@ -730,16 +742,17 @@ def test_integer_array_constructor():
730
742
expected = integer_array ([1 , 2 , 3 , np .nan ], dtype = "int64" )
731
743
tm .assert_extension_array_equal (result , expected )
732
744
733
- with pytest .raises (TypeError ):
745
+ msg = r".* should be .* numpy array. Use the 'integer_array' function instead"
746
+ with pytest .raises (TypeError , match = msg ):
734
747
IntegerArray (values .tolist (), mask )
735
748
736
- with pytest .raises (TypeError ):
749
+ with pytest .raises (TypeError , match = msg ):
737
750
IntegerArray (values , mask .tolist ())
738
751
739
- with pytest .raises (TypeError ):
752
+ with pytest .raises (TypeError , match = msg ):
740
753
IntegerArray (values .astype (float ), mask )
741
-
742
- with pytest .raises (TypeError ):
754
+ msg = r"__init__\(\) missing 1 required positional argument: 'mask'"
755
+ with pytest .raises (TypeError , match = msg ):
743
756
IntegerArray (values )
744
757
745
758
@@ -787,7 +800,11 @@ def test_integer_array_constructor_copy():
787
800
)
788
801
def test_to_integer_array_error (values ):
789
802
# error in converting existing arrays to IntegerArrays
790
- with pytest .raises (TypeError ):
803
+ msg = (
804
+ r"(:?.* cannot be converted to an IntegerDtype)"
805
+ r"|(:?values must be a 1D list-like)"
806
+ )
807
+ with pytest .raises (TypeError , match = msg ):
791
808
integer_array (values )
792
809
793
810
@@ -1002,7 +1019,8 @@ def test_ufuncs_binary_int(ufunc):
1002
1019
@pytest .mark .parametrize ("values" , [[0 , 1 ], [0 , None ]])
1003
1020
def test_ufunc_reduce_raises (values ):
1004
1021
a = integer_array (values )
1005
- with pytest .raises (NotImplementedError ):
1022
+ msg = r"The 'reduce' method is not supported."
1023
+ with pytest .raises (NotImplementedError , match = msg ):
1006
1024
np .add .reduce (a )
1007
1025
1008
1026
0 commit comments