File tree 2 files changed +17
-10
lines changed
2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -686,16 +686,19 @@ def construct_from_string(cls, string):
686
686
>>> DatetimeTZDtype.construct_from_string('datetime64[ns, UTC]')
687
687
datetime64[ns, UTC]
688
688
"""
689
- msg = "Could not construct DatetimeTZDtype from '{}'"
690
- try :
691
- match = cls ._match .match (string )
692
- if match :
693
- d = match .groupdict ()
694
- return cls (unit = d ['unit' ], tz = d ['tz' ])
695
- except Exception :
696
- # TODO(py3): Change this pass to `raise TypeError(msg) from e`
697
- pass
698
- raise TypeError (msg .format (string ))
689
+ if isinstance (string , compat .string_types ):
690
+ msg = "Could not construct DatetimeTZDtype from '{}'"
691
+ try :
692
+ match = cls ._match .match (string )
693
+ if match :
694
+ d = match .groupdict ()
695
+ return cls (unit = d ['unit' ], tz = d ['tz' ])
696
+ except Exception :
697
+ # TODO(py3): Change this pass to `raise TypeError(msg) from e`
698
+ pass
699
+ raise TypeError (msg .format (string ))
700
+
701
+ raise TypeError ("Could not construct DatetimeTZDtype" )
699
702
700
703
def __unicode__ (self ):
701
704
return "datetime64[{unit}, {tz}]" .format (unit = self .unit , tz = self .tz )
Original file line number Diff line number Diff line change @@ -232,6 +232,10 @@ def test_construct_from_string_raises(self):
232
232
with pytest .raises (TypeError , match = "notatz" ):
233
233
DatetimeTZDtype .construct_from_string ('datetime64[ns, notatz]' )
234
234
235
+ with pytest .raises (TypeError ,
236
+ match = "^Could not construct DatetimeTZDtype$" ):
237
+ DatetimeTZDtype .construct_from_string (['datetime64[ns, notatz]' ])
238
+
235
239
def test_is_dtype (self ):
236
240
assert not DatetimeTZDtype .is_dtype (None )
237
241
assert DatetimeTZDtype .is_dtype (self .dtype )
You can’t perform that action at this time.
0 commit comments