Skip to content

Commit a965178

Browse files
committed
Fix interevent tests
1 parent 7ef96dd commit a965178

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

flowmachine/flowmachine/features/subscriber/interevent_period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _make_query(self):
110110
sql = f"""
111111
SELECT
112112
subscriber,
113-
EXTRACT(epoch FROM value/{self.time_divisor}) AS value
113+
FLOOR(EXTRACT(epoch FROM value)/{self.time_divisor}) AS value
114114
FROM ({self.event_interval.get_query()}) AS U
115115
"""
116116

flowmachine/tests/test_subscriber_interevent_gap.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _intervent_period(*, start, stop, direction, subset, stat):
3535
agg = events.groupby("subscriber").agg(
3636
lambda x: getattr(x, postgres_stat_to_pandas_stat[stat])()
3737
)
38-
agg = (pd.to_numeric(agg["duration"]) / 1000000000.0).to_dict()
38+
agg = (agg["duration"].astype("timedelta64[s]")).to_dict()
3939

4040
return agg
4141

@@ -59,15 +59,19 @@ def test_interevent_period(
5959
"""
6060

6161
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",
6367
)
6468
df = get_dataframe(query).set_index("subscriber")
6569
sample = df.sample(n=5)
6670
want = intervent_period(
6771
start=start, stop=stop, direction=direction, stat=stat, subset=sample
6872
)
6973
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)
7175

7276

7377
@pytest.mark.parametrize(
@@ -95,9 +99,7 @@ def test_interevent_interval(
9599
start=start, stop=stop, direction=direction, stat=stat, subset=sample
96100
)
97101
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)
101103

102104

103105
@pytest.mark.parametrize("kwarg", ["direction", "statistic"])

0 commit comments

Comments
 (0)