File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -569,16 +569,16 @@ def construct_from_string(cls, string):
569
569
>>> DatetimeTZDtype.construct_from_string('datetime64[ns, UTC]')
570
570
datetime64[ns, UTC]
571
571
"""
572
- msg = "could not construct DatetimeTZDtype" " "
572
+ msg = "Could not construct DatetimeTZDtype from {} "
573
573
try :
574
574
match = cls ._match .match (string )
575
575
if match :
576
576
d = match .groupdict ()
577
577
return cls (unit = d ['unit' ], tz = d ['tz' ])
578
- else :
579
- raise TypeError (msg )
580
- except ValueError :
581
- raise TypeError (msg )
578
+ except Exception :
579
+ # TODO(py3): Change this pass to ` raise TypeError(msg) from e`
580
+ pass
581
+ raise TypeError (msg . format ( string ) )
582
582
583
583
def __unicode__ (self ):
584
584
return "datetime64[{unit}, {tz}]" .format (unit = self .unit , tz = self .tz )
Original file line number Diff line number Diff line change @@ -189,6 +189,10 @@ def test_construction_from_string(self):
189
189
pytest .raises (TypeError ,
190
190
lambda : DatetimeTZDtype .construct_from_string ('foo' ))
191
191
192
+ def test_construct_from_string_raises (self ):
193
+ with pytest .raises (TypeError , match = "notatz" ):
194
+ DatetimeTZDtype .construct_from_string ('datetime64[ns, notatz]' )
195
+
192
196
def test_is_dtype (self ):
193
197
assert not DatetimeTZDtype .is_dtype (None )
194
198
assert DatetimeTZDtype .is_dtype (self .dtype )
You can’t perform that action at this time.
0 commit comments