Skip to content

Commit cd252e3

Browse files
authored
Merge pull request #7192 from ales-erjavec/oweditdomain-reinterpret-numeric-as-time
[ENH ] Edit Domain: Reinterpret Numeric as Time with Unit
2 parents 0b0423f + 02f6ac2 commit cd252e3

File tree

6 files changed

+371
-111
lines changed

6 files changed

+371
-111
lines changed

Orange/data/tests/test_variable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,11 @@ def test_repr_value(self):
756756
var = TimeVariable('time')
757757
self.assertEqual(var.repr_val(Value(var, 416.3)), '416.3')
758758

759+
def test_repr_value_out_of_bounds(self):
760+
var = TimeVariable("T", have_date=True, have_time=True)
761+
self.assertEqual(var.repr_val(1e300), "?")
762+
self.assertEqual(var.repr_val(-1e300), "?")
763+
759764
def test_have_date_have_time_in_construct(self):
760765
"""Test if have_time and have_date is correctly set"""
761766
var = TimeVariable('time', have_date=1)

Orange/data/variable.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,15 @@ def repr_val(self, val):
11231123
if val < 0:
11241124
if microseconds:
11251125
seconds, microseconds = seconds - 1, int(1e6) + microseconds
1126-
date = datetime.fromtimestamp(0, tz=self.timezone) + timedelta(seconds=seconds)
1126+
try:
1127+
date = datetime.fromtimestamp(0, tz=self.timezone) + timedelta(seconds=seconds)
1128+
except (OverflowError, ValueError):
1129+
return "?"
11271130
else:
1128-
date = datetime.fromtimestamp(seconds, tz=self.timezone)
1131+
try:
1132+
date = datetime.fromtimestamp(seconds, tz=self.timezone)
1133+
except (OverflowError, ValueError):
1134+
return "?"
11291135
date = str(date.replace(microsecond=microseconds))
11301136

11311137
if self.have_date and not self.have_time:

0 commit comments

Comments
 (0)