File tree 2 files changed +8
-1
lines changed
2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -882,7 +882,11 @@ def construct_from_string(cls, string):
882
882
return cls (freq = string )
883
883
except ValueError :
884
884
pass
885
- raise TypeError (f"Cannot construct a 'PeriodDtype' from '{ string } '" )
885
+ if isinstance (string , str ):
886
+ msg = f"Cannot construct a 'PeriodDtype' from '{ string } '"
887
+ else :
888
+ msg = f"'construct_from_string' expects a string, got { type (string )} "
889
+ raise TypeError (msg )
886
890
887
891
def __str__ (self ) -> str_type :
888
892
return self .name
Original file line number Diff line number Diff line change @@ -408,6 +408,9 @@ def test_construction_from_string(self):
408
408
with pytest .raises (TypeError ):
409
409
PeriodDtype .construct_from_string ("datetime64[ns, US/Eastern]" )
410
410
411
+ with pytest .raises (TypeError , match = "list" ):
412
+ PeriodDtype .construct_from_string ([1 , 2 , 3 ])
413
+
411
414
def test_is_dtype (self ):
412
415
assert PeriodDtype .is_dtype (self .dtype )
413
416
assert PeriodDtype .is_dtype ("period[D]" )
You can’t perform that action at this time.
0 commit comments