@@ -361,7 +361,7 @@ def test_hash_vs_equality(self, dtype):
361
361
assert hash (dtype ) == hash (dtype3 )
362
362
363
363
def test_construction (self ):
364
- with pytest .raises (ValueError ):
364
+ with pytest .raises (ValueError , match = "Invalid frequency: xx" ):
365
365
PeriodDtype ("xx" )
366
366
367
367
for s in ["period[D]" , "Period[D]" , "D" ]:
@@ -414,21 +414,25 @@ def test_construction_from_string(self, dtype):
414
414
assert is_dtype_equal (dtype , result )
415
415
result = PeriodDtype .construct_from_string ("period[D]" )
416
416
assert is_dtype_equal (dtype , result )
417
- with pytest .raises (TypeError ):
418
- PeriodDtype .construct_from_string ("foo" )
419
- with pytest .raises (TypeError ):
420
- PeriodDtype .construct_from_string ("period[foo]" )
421
- with pytest .raises (TypeError ):
422
- PeriodDtype .construct_from_string ("foo[D]" )
423
-
424
- with pytest .raises (TypeError ):
425
- PeriodDtype .construct_from_string ("datetime64[ns]" )
426
- with pytest .raises (TypeError ):
427
- PeriodDtype .construct_from_string ("datetime64[ns, US/Eastern]" )
428
417
429
418
with pytest .raises (TypeError , match = "list" ):
430
419
PeriodDtype .construct_from_string ([1 , 2 , 3 ])
431
420
421
+ @pytest .mark .parametrize (
422
+ "string" ,
423
+ [
424
+ "foo" ,
425
+ "period[foo]" ,
426
+ "foo[D]" ,
427
+ "datetime64[ns]" ,
428
+ "datetime64[ns, US/Eastern]" ,
429
+ ],
430
+ )
431
+ def test_construct_dtype_from_string_invalid_raises (self , string ):
432
+ msg = f"Cannot construct a 'PeriodDtype' from '{ string } '"
433
+ with pytest .raises (TypeError , match = re .escape (msg )):
434
+ PeriodDtype .construct_from_string (string )
435
+
432
436
def test_is_dtype (self , dtype ):
433
437
assert PeriodDtype .is_dtype (dtype )
434
438
assert PeriodDtype .is_dtype ("period[D]" )
@@ -475,7 +479,9 @@ def test_basic(self, dtype):
475
479
476
480
def test_empty (self ):
477
481
dt = PeriodDtype ()
478
- with pytest .raises (AttributeError ):
482
+ # https://github.com/pandas-dev/pandas/issues/27388
483
+ msg = "object has no attribute 'freqstr'"
484
+ with pytest .raises (AttributeError , match = msg ):
479
485
str (dt )
480
486
481
487
def test_not_string (self ):
@@ -764,11 +770,13 @@ def test_order_hashes_different(self, v1, v2):
764
770
assert c1 is not c3
765
771
766
772
def test_nan_invalid (self ):
767
- with pytest .raises (ValueError ):
773
+ msg = "Categorical categories cannot be null"
774
+ with pytest .raises (ValueError , match = msg ):
768
775
CategoricalDtype ([1 , 2 , np .nan ])
769
776
770
777
def test_non_unique_invalid (self ):
771
- with pytest .raises (ValueError ):
778
+ msg = "Categorical categories must be unique"
779
+ with pytest .raises (ValueError , match = msg ):
772
780
CategoricalDtype ([1 , 2 , 1 ])
773
781
774
782
def test_same_categories_different_order (self ):
0 commit comments