Coverage for jstark / features / recency_days.py: 100%
14 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-23 22:34 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-23 22:34 +0000
1"""RecencyDays feature"""
3import pyspark.sql.functions as f
4from pyspark.sql import Column
6from jstark.features.min_feature import Min
9class RecencyDays(Min):
10 def column_expression(self) -> Column:
11 return f.datediff(f.lit(self.as_at), f.col("Timestamp"))
13 def default_value(self) -> Column:
14 return f.lit(0)
16 @property
17 def description_subject(self) -> str:
18 return "Minimum number of days since occurrence"
20 @property
21 def commentary(self) -> str:
22 return (
23 "This could be particularly useful (for example) in a grocery retailer "
24 + "for determining when a customer most recently bought a product or "
25 + " when a product was most recently bought in a store"
26 + "Also note that this is very similar to "
27 + f"MostRecentPurchaseDate_{self.feature_period.mnemonic} "
28 + "so consider which of these "
29 + "features is most useful to you."
30 )