@@ -35,7 +35,7 @@ def _intervent_period(*, start, stop, direction, subset, stat):
35
35
agg = events .groupby ("subscriber" ).agg (
36
36
lambda x : getattr (x , postgres_stat_to_pandas_stat [stat ])()
37
37
)
38
- agg = (pd . to_numeric ( agg ["duration" ]) / 1000000000.0 ).to_dict ()
38
+ agg = (agg ["duration" ]. astype ( "timedelta64[s]" ) ).to_dict ()
39
39
40
40
return agg
41
41
@@ -59,15 +59,19 @@ def test_interevent_period(
59
59
"""
60
60
61
61
query = IntereventPeriod (
62
- start = start , stop = stop , direction = direction , statistic = stat
62
+ start = start ,
63
+ stop = stop ,
64
+ direction = direction ,
65
+ statistic = stat ,
66
+ time_resolution = "second" ,
63
67
)
64
68
df = get_dataframe (query ).set_index ("subscriber" )
65
69
sample = df .sample (n = 5 )
66
70
want = intervent_period (
67
71
start = start , stop = stop , direction = direction , stat = stat , subset = sample
68
72
)
69
73
assert query .column_names == ["subscriber" , "value" ]
70
- assert (sample ["value" ] * query . time_divisor ).to_dict () == pytest .approx (want )
74
+ assert (sample ["value" ]).to_dict () == pytest .approx (want )
71
75
72
76
73
77
@pytest .mark .parametrize (
@@ -95,9 +99,7 @@ def test_interevent_interval(
95
99
start = start , stop = stop , direction = direction , stat = stat , subset = sample
96
100
)
97
101
assert query .column_names == ["subscriber" , "value" ]
98
- assert (pd .to_numeric (sample ["value" ]) / 1000000000.0 ).to_dict () == pytest .approx (
99
- want
100
- )
102
+ assert (sample ["value" ].astype ("timedelta64[s]" )).to_dict () == pytest .approx (want )
101
103
102
104
103
105
@pytest .mark .parametrize ("kwarg" , ["direction" , "statistic" ])
0 commit comments