File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ from hypothesis import given
2
+ import hypothesis .strategies as st
1
3
import numpy as np
2
4
import pytest
3
5
@@ -51,6 +53,34 @@ def test_td64_sum_empty(skipna):
51
53
assert result == pd .Timedelta (0 )
52
54
53
55
56
+ @given (
57
+ st .integers (
58
+ min_value = 0 ,
59
+ max_value = 10 ** (np .finfo (np .float64 ).precision ),
60
+ ).map (pd .Timedelta )
61
+ )
62
+ def test_td64_summation_retains_ns_precision_over_expected_range (value : pd .Timedelta ):
63
+ result = pd .Series (value ).sum ()
64
+
65
+ assert result == value
66
+
67
+
68
+ @given (
69
+ st .integers (
70
+ min_value = 10 ** (np .finfo (np .float64 ).precision ),
71
+ max_value = pd .Timedelta .max .value ,
72
+ )
73
+ .filter (lambda i : int (np .float64 (i )) != i )
74
+ .map (pd .Timedelta )
75
+ )
76
+ def test_td64_summation_loses_ns_precision_if_float_conversion_rounds (
77
+ value : pd .Timedelta ,
78
+ ):
79
+ result = pd .Series (value ).sum ()
80
+
81
+ assert result != value
82
+
83
+
54
84
def test_td64_summation_overflow ():
55
85
# GH#9442
56
86
ser = Series (pd .date_range ("20130101" , periods = 100000 , freq = "H" ))
You can’t perform that action at this time.
0 commit comments