Skip to content

Commit cf2ac59

Browse files
author
Matthias Ludwig
committed
Another exception handled while converting something into a datetime
1 parent c877bb8 commit cf2ac59

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandasqt/models/DataFrameModel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ def setData(self, index, value, role=Qt.DisplayRole):
350350
value = value.toString(self.timestampFormat)
351351
try:
352352
value = pandas.Timestamp(value)
353-
except ValueError, e:
354-
raise
353+
except Exception:
354+
raise Exception, u"Can't convert '{0}' into a datetime".format(value)
355355
return False
356356
else:
357357
raise TypeError, "try to set unhandled data type"

tests/test_DataFrameModel.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ def test_date(self, model, index):
414414
assert model.data(index, role=DATAFRAME_ROLE) == newDate
415415
assert isinstance(model.data(index, role=DATAFRAME_ROLE), pandas.Timestamp)
416416

417-
assert model.setData(index, 'foobar') == False
417+
with pytest.raises(Exception) as err:
418+
model.setData(index, 'foobar')
419+
assert "Can't convert 'foobar' into a datetime" in str(err.value)
418420

419421
@pytest.mark.parametrize(
420422
"value, dtype, precision", [
@@ -604,7 +606,7 @@ def test_add_column(self, model, newColumns):
604606
if isinstance(_type, numpy.dtype):
605607
defaultVal = _type.type()
606608
if _type.type == numpy.datetime64:
607-
defaultVal = pandas.Timestamp('')
609+
defaultVal = pandas.Timestamp('1-01-01 00:00:00')
608610
else:
609611
defaultVal = _type()
610612

0 commit comments

Comments
 (0)