Skip to content

Commit 1672463

Browse files
authored
fixes btrdb pointwidth.from_timedelta issue (#68)
1 parent 6e0b67c commit 1672463

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

btrdb/utils/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def from_timedelta(cls, delta):
5858
specified duration. Because pointwidths are in powers of 2, be sure to check
5959
that the returned real duration is sufficient.
6060
"""
61-
return cls.from_nanoseconds(delta.total_seconds()*1e9)
61+
return cls.from_nanoseconds(int(delta.total_seconds()*1e9))
6262

6363
@classmethod
6464
def from_nanoseconds(cls, nsec):

tests/btrdb/utils/test_general.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ class TestPointwidth(object):
2525
(timedelta(days=30), 51),
2626
(timedelta(days=7), 49),
2727
(timedelta(days=1), 46),
28-
(timedelta(hours=4), 45),
29-
(timedelta(minutes=15), 40),
30-
(timedelta(seconds=30), 29),
28+
(timedelta(hours=4), 43),
29+
(timedelta(minutes=15), 39),
30+
(timedelta(seconds=30), 34),
3131
])
32-
def test_from_nanoseconds(self, delta, expected):
32+
33+
def test_from_timedelta(self, delta, expected):
3334
"""
34-
Test getting the closest point width from nanoseconds
35+
Test getting the closest point width from a timedelta
3536
"""
36-
assert pointwidth.from_nanoseconds(nsec) == expected
37+
assert pointwidth.from_timedelta(delta) == expected
3738

3839
@pytest.mark.parametrize("nsec, expected", [
3940
(ns_delta(days=365), 54),
@@ -44,6 +45,7 @@ def test_from_nanoseconds(self, delta, expected):
4445
(ns_delta(minutes=30), 40),
4546
(ns_delta(seconds=1), 29),
4647
])
48+
4749
def test_from_nanoseconds(self, nsec, expected):
4850
"""
4951
Test getting the closest point width from nanoseconds

0 commit comments

Comments
 (0)